V
V
Vitaly2018-11-01 13:11:58
Algorithms
Vitaly, 2018-11-01 13:11:58

How to pick up 5 random numbers if there is only the arithmetic mean of these numbers?

How to pick up 5 random numbers if there is only the arithmetic mean of these numbers, and these random numbers should be in a certain range in my case from 60 to 100?
The bottom line is that I have a rating that looks like this:
5bdacf213d333672175777.png
But the problem is that now I have only the arithmetic mean of this rating (in this case, the number 89), and there are no numbers from which this arithmetic mean was formed, (it just happened, it just looked different before, and it consisted only of one number). And now there is a task to add values ​​​​to this rating from which the arithmetic mean should eventually be formed, which we already have, and which should not change, but there is a condition for these values ​​to be random from the range from 60 to 100. I hope it's understandable. Can you tell me if there is a formula that can be used to calculate these values?
Update: Thanks to everyone who took part in solving the problem. The GavriKos solution suited me the best , although the others are not bad either. Good luck everyone!!!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
GavriKos, 2018-11-01
@ya-vitaliy

Make all 5 numbers equal to 89. Then take any 2 numbers from these five. One is increased by n, the other is decreased. It is important to choose n randomly, but so that when increasing / decreasing the numbers do not go beyond the ranges (which is also simple in general). Repeat this as many times as you want.

I
imhuman, 2018-11-01
@imhuman

Generate a number from the range of 60-100, then calculate a pair for it, with the condition that the arithmetic mean of the pair of numbers was close to the target (enter some kind of deviation factor X). Then a couple more numbers according to the same principle, and calculate the last number as Sergei Tikhonov advised you . On a series of experiments, select X so that the numbers seem random and at the same time there are no outliers beyond 60-100 for the last 5th number. Somehow you can try.

X
x_dmitry_x, 2018-11-01
@x_dmitry_x

import random

def get_randoms(n, avg, min_val, max_val, repeats=20):
    result = [avg] * n
    for i in range(repeats):
        i1, i2 = random.sample(range(n), 2) # выбираем 2 случайных индекса
        v1, v2 = (result[i1], result[i2]) 
        max_delta = min(v1 - min_val, max_val - v2)
        rand_delta = random.randint(0, max_delta)
        v1 -= rand_delta
        v2 += rand_delta
        result[i1] = v1
        result[i2] = v2

    return result

randoms = get_randoms(5, 89, 60, 100)
print(randoms, sum(randoms) / 5) # [95, 71, 98, 92, 89] 89.0

randoms = get_randoms(5, 89, 60, 100, 50)
print(randoms, sum(randoms) / 5) # [95, 97, 75, 81, 97] 89.0

D
dmshar, 2018-11-01
@dmshar

Sorry, but I have to put a fly in the ointment in your honey barrel.
The matter is that operation "restoration on the average" - is absolutely senseless semantically. Those. "recovered" data cannot be used for any analysis. Categorically and absolutely.
In other words, real "past" data that you can work with and extract meaningful information from them - well, for example, see how they change over time - as it was the average, it remains. All recovered data for this - and no other analysis - is not suitable. Any such attempt is a clear falsification.
Then the question is - why "restore" them? It's more honest to simply indicate - "data not available".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question