View Single Post
  #14  
Old 11-17-2007, 10:09 AM
BruceZ BruceZ is offline
Senior Member
 
Join Date: Sep 2002
Posts: 4,078
Default Re: Looking for event-based random number generator

[ QUOTE ]
You can actually generate a series of random numbers that are normally distributed by adding together 2 numbers that are randomly generated by a linear distribution.

[/ QUOTE ]

Numbers generated this way are not normally distributed. You need to add more than 2 numbers in order to adequately approximate a normal distribution by the central limit theorem. Adding 2 uniformly distributed numbers gives a triangular shaped density function, not a normal bell curve.

[ QUOTE ]
I remembered this because when you roll 2 dice, the sum of the dice is a standard distribution.

[/ QUOTE ]

The sum of 2 dice follows the discreet version of the triangular shaped density function.


[ QUOTE ]
n1 = rand()*std*2.45
n2 = rand()*std*2.45
num = mean + n1 + n2 - std*2.45

[/ QUOTE ]

If rand() is the standard uniform distribution on [0,1], this will generate numbers with the given mean and standard deviation, but the density function will be triangular in shape.


[ QUOTE ]
Why 2.45? I don't know. But it works.

[/ QUOTE ]

The value 2.45 is an approximation for sqrt(6). Your formula can be written as

num = mean + sqrt(6)*std*[rand() + rand() - 1]

The variance of the uniform distribution rand() is 1/12, so the variance of rand() + rand() is 1/6. Subtracting 1 does not change the variance, so the standard deviation of the term in brackets is 1/sqrt(6), so multiplying by sqrt(6)*std gives the desired standard deviation.

This post gives a method for generating normally distributed random numbers from uniformly distributed random numbers if you have access to the inverse normal function as in Excel. Another method is to use the Box-Muller transformation. I have generated normally distributed random numbers by simply adding together a sufficiently large number of uniformly distributed random numbers (as from the rand() function).

If the OP requires that every set of n numbers he generates has the same mean and standard deviation, then he can use one of the other methods in this thread to scale the final numbers to achieve this. Normally distributed numbers would show some variation in the actual mean and standard deviation for each set of n numbers. These variations become small as n becomes large. The methods in this post will generate numbers which are distributed as a normal distribution with the desired mean and standard deviation, and the actual computed mean and standard deviation for each set of n numbers will vary as they should.
Reply With Quote