The Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.stat.math

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Michael Whitbeck

Posts: 4
Registered: 12/15/04
normal distribution generator in C
Posted: Jul 11, 1996 7:24 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.