Gaussian (Normal) Distribution. Function randomo returns a uniformly
distributed random variable in the range , which means that there is an
equal probability of any given number in the range occurring on a given call
to the function. Another type of random distribution is the Gaussian
distribution, in which the random value takes on the classic bellshaped curve
shown in Figure 5.9. A Gaussian distribution with an average of and a
standard deviation of is called a standardized normal distribution, and
the probability of any given value occurring in the standardized normal
distribution is given by the equation
It is possible to generate a random variable with a standardized normal
distribution starting from a random variable with a uniform distribution in
the range as follows.
1\. Select two uniform random variables and from the range
such that . To do this, generate two uniform
random variables in the range , and see if the sum of their squares
happens to be less than . If so, use them. If not, try again.
2\. Then each of the values and in the equations that follow
will be a normally distributed random variable.
where
a In is the natural logarithm (log to the base e). Write a function that
returns a normally distributed random value cach time that it is called. Test
your function by getting 1000 random values, calculating the standard
deviation, and plotting a histogram of the distribution. How close to
was the standard deviation?