Uniform random generator and Gaussian (or Normal) generator

hi , i am looking for a uniform random generator and gaussian(or normal) random generator. i want to generate integer numbers between [0 , RAND_MAX] . Do you know any code or any site that can help ??

i want to use the generators to initialize a one dimensional table[] . any help?
Last edited on
Two uniform generators are linear congruential generators (rand()) and Mersenne Twister.
No idea about normal generators. You should read this: http://en.wikipedia.org/wiki/PRNG#Non-uniform_generators
Last edited on
Off the top of my head, from statistics I recall that if X and Y are uniformly distributed random variables, then X+Y and X-Y are both normally distributed random numbers, however I do not remember how to compute the mean or variance.

This should give you enough info to do a pointed search online.
Correct me if I'm wrong, but boost does provide a normal distribution generator (and many others)
Check this link:
Last edited on
Statistical stuff i can help with. Payback for all the programming help i've gotten here. An easy way to to get Normal or Gaussian from a uniform number generator is to add several of them together. The Central Limit Theorem tells you that the sum of i.i.d. (independent idendically distributed) random numbers approaches Gaussian as the number of terms being summed gets large. (10 is probably large enough unless you're very concerned about proper statistics on very rare events.) Here's a bit of code toi implement this approach.

double GaussNum = 0.0;
int NumInSum = 10;
for(int i = 0; i < NumInSum; i++)
GaussNum += ((double)rand()/(double)RAND_MAX - 0.5);
GaussNum = GaussNum*sqrt((double)12/(double)NumInSum);

That should work well enough unless you're focus is on rare events (say events that are less and 0.5% probability). If that's the case, then rand() won't be a good enough generator for you. If you can get your hands on a copy of Principles of Mathematical Finance by Mark Joshi, you'll find a thorough discussiion of extra low dispersion generators.
Last edited on
You're almost two months late.
Topic archived. No new replies allowed.