Re: normal distribution random number generation

• To: mathgroup at smc.vnet.net
• Subject: [mg51159] Re: normal distribution random number generation
• Date: Wed, 6 Oct 2004 04:35:12 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 10/5/04 at 4:36 AM, cjkunkel at marauder.millersville.edu (Chris
Kunkel) wrote:

>Recently I have encountered a problem in Mathematica's normal
>distribution random number generator.  The problem arises when I
>look at the distribution of averages of a list of theses numbers.
>That is, I generate 1000 numbers and take their average.  I do this
>a number of times and the plot a frequency distribution.
>Consistently it seems to be skewed positive.  Specifically, the
>number of occurrences less than 3 standard deviations is consistent
>with the expected number, but the number greater than 3 is always
>larger (in some cases about twice the expected number).

>I was wondering if anyone else has noticed this and knows of a fix.
>Also, does anyone have code for a good quality normal distribution
>random number generator?

I don't think this is a problem with the code for generating normal deviates. Instead, I think it is a problem with the algorithm to generate uniform deviates used by the code to generate normal deviates.

For reals, Mathematica uses a subtract with borrow algorithm. Unforunately, this algorithm is flawed. This has been discussed previously in this forum. The work around is to generate random integers between 0 and 2^30-1. For these integers, Mathematica uses the Wolfram rule 30 cellular automaton which does not seem to have any problems.

If you do the following:

Unprotect[Random];

Random[]:=(Random[Integer,2^30-1]/2^30.+Random[Integer,2^30-1])/2^30.

Random[Real,{a_Real,b_Real}]:=a+Random[]*(b-a)

Random[Real,b_Real]:=Random[Real,{0,b}]

Random[Real]:=Random[Real,{0,1}]

Protect[Random];

you will have modified Random to use the Wolfram rule 30 cellular automaton and avoid the subtract with borrow algorithm. The main consequence of this is Random will now be considerably slower.

The other alternative would be to create you own pseudo-random number generator and patch Random as above with it. But be aware, creating pseudo-random number generators is not an easy task. Unless you know what you are doing, you are quite likely to wind up with something even worse than the subtract with borrow algorithm Mathematica uses.
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: Oddities of Plot[]
• Next by Date: Re: normal distribution random number generation
• Previous by thread: normal distribution random number generation
• Next by thread: Re: normal distribution random number generation