Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: normal distribution generator in C
Replies: 2   Last Post: Jul 17, 1996 10:29 PM

 Messages: [ Previous | Next ]
 Michael Whitbeck Posts: 4 Registered: 12/15/04
normal distribution generator in C
Posted: Jul 11, 1996 7:24 PM

I use the following routine to make a pseudo-random number with a
normal distribution:

double nrml()
/* a normal random number in range -1 to 1 i.e. N(0,1) */
{
double r,u,v;
do {
do {u = rnmu();} while (u == 0);
v = rnmu();
v = 1.7156*(v-.5);
r = v/u;
}while (r*r > -4.00*log(u));
return r;
}

where rnmu() delivers a pseudo-random number with a uniform
distribution.

At the moment it is adequate however if someone could point me to a
better one (preferably in C) I'd appreciate it. I also welcome comments
on how to improve this one; rather inefficient.

Mike
whitbeck1@llnl.gov

Date Subject Author
7/11/96 Michael Whitbeck
7/17/96 nick nelson