How to generate random numbers with a specific mean?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
I need to generate a set of random numbers with a target mean. For example, random numbers on (0,100) with a mean of 65.

I found a bunch of websites that talked about generating random numbers with a set mean and std dev using the Norm.Inv function, but those numbers would follow a Normal distribution and it wasn't clear to me how I would get them to stay within the (0-100) range and use all of it. I suppose a Normal distribution would work if there is one that goes to zero at 0 and 100 and not beyond. Is there?

I came up with this formula which seems to work.

VBA Code:
=IF(RANDBETWEEN(0,100)<65,RANDBETWEEN(65,100),RANDBETWEEN(0,65))

It does seem to tend toward the correct average. I wasn't sure if the "<65" should be "<=65" and/or if one of the ranges should be (66,100) or (0,64).

Any comments? Is there a better way?
 
Does that qualify as "working"?
If the variance between the required mean and the output of the formula is within your acceptable tolerance then it qualifies.

With the test that I ran based on the parameters you specified in post 1 the mean was coming out between 37.78 and 83.36. I would say that the difference between the actual mean and the specified target mean of 65 is too great for the method to be considered as working, but that is just my personal opinion.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You didn't indicate the spread of the random variate you want. A simple robust (and one correct) solution is to use the inverse of the Beta distribution. It has two shape parameters, alpha and beta, and ranges from 0 to 1. Its mean is alpha/(alpha+beta), and its standard deviation is available on wikipedia; lower values of alpha and beta (alpha>0, beta>0) give more spread. To get your variate, just scale the function and shift, using your values for alpha and beta: =1+FLOOR.MATH(BETA.INV(RAND(),alpha,beta)*100)
To get a sense of how your distribution will look for the bariates, use beta.dist. Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top