I need to create numbers in a range with a specific mean. I tried using the RandBetween function in excel, however, I was not able to take into account the mean. Is there a way to get random numbers from a distribution that fit the criteria?
Asked
Active
Viewed 341 times
1
-
3You can simply use 4. This is in the range (2, 10), has a mean of 4, and is a [well documented random number](https://xkcd.com/221/). – Eric Postpischil Apr 19 '22 at 18:36
-
Seriously, there are infinitely many probability distributions in the range (2, 10) that have a mean of 4. You need to provide more information. Does the range include or exclude the endpoints, 2 and 10? Do you want to generate only integers? Do you have any criteria on how the numbers in [2, 4) and (4, 10] should be distributed? E.g., do you want just a few 10s and lots of 5s, or should all integers from 5 to 10 have equal probabilities? – Eric Postpischil Apr 19 '22 at 18:39
-
A distribution in math like the Poisson, exponential, gamma, or beta distribution in probability. I was trying to generate random numbers in that range in excel with a mean of 4. Is there a way to generate random numbers in a range with a mean in excel? – Purple_blue Apr 19 '22 at 18:43
-
the bounds are included and I need whole numbers in that range. I tried using a Poisson, normal, and beta distribution in excel but there is nowhere to specify the mean. – Purple_blue Apr 19 '22 at 18:45
-
Does this answer your question? [Generate N random numbers in given ranges that sum up to a given sum](https://stackoverflow.com/questions/19877059/generate-n-random-numbers-in-given-ranges-that-sum-up-to-a-given-sum) – Dave Apr 19 '22 at 18:55
-
YEs, to an extent. I need to be able to create a distribution that has a mean of 4 and ranges from 2 to 10. So, it would be skewed right and single peaked. – Purple_blue Apr 19 '22 at 23:15
-
Does this answer your question? [Is there an efficient way to generate N random integers in a range that have a given sum or average?](https://stackoverflow.com/questions/61393463/is-there-an-efficient-way-to-generate-n-random-integers-in-a-range-that-have-a-g) – Peter O. Jun 21 '22 at 22:35
2 Answers
0
Assume there is a function rand()
the returns an equal distribution random number between 0 and 1.
function myrand(minValue, maxValue, meanValue)
{
tc = (maxValue - meanValue)/(maxValue - minValue);
t = rand();
if(t <= tc)
{
return (1-t/tc)*minValue + t/tc*meanValue;
} else {
return (1-(t-tc)/(1-tc))*meanValue + (t-tc)/(1-tc)*maxValue;
}
}
and call myrand(2.0,10.0,4.0)
Exmplanation:
create a bi-modal distribution with area under the curve equal to the mean value.
The x-axis goes between 0 and 1, and is the result of the rand()
function, and the y-axis is the function return.
On average the mean value equals the area under the curve, something that is proved in calculus classes.

JAlex
- 1,486
- 8
- 19
-1
Given a probability mass function or a probability density function there are several algorithms able to extract pseudo-random numbers from it. In this Wikipedia page: https://en.wikipedia.org/wiki/Pseudo-random_number_sampling there are several examples and links.

apelle
- 144
- 1
- 9