Pseudorandom Number Generator

As far as I know, there is no pseudo random number generator for c. I don't know much about probability and statistics, but does anyone else know of a method or function (or perhaps a library that contains a function) that returns a pseudo random scalar value drawn from a normal distribution with mean 0 and standard deviation 1?

I was able to find some code on the internet, but it uses the rand() function, which I heard is not all that random in c.
Here's the code:

As far as I know, there is no pseudo random number generator for c. I don't know much about probability and statistics, but does anyone else know of a method or function (or perhaps a library that contains a function) that returns a pseudo random scalar value drawn from a normal distribution with mean 0 and standard deviation 1?

I was able to find some code on the internet, but it uses the rand() function, which I heard is not all that random in c.

How can there be no prng for C when you've just mentioned it - rand. rand is nowhere near as bad as some people think. For almost all purposes the results are indistinguishable from anything better, assuming you use it properly, i.e. not calling srand each time etc.
Switching from rand to something else without working out that rand isn't good enough is premature pessimation/optimisation (you choose).

My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger

Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

People probably shouldn't be put off just because it's possible that there might be some rubbish implementation out there somewhere. Implementations of common compilers such as MSVC++ are "pretty good", and that all that matters to most people.

rand() is good for student dice rolling problems, and little else.

This is exactly the kind of broad over-generalisation I was referring to. The number of applications rand is perfectly suited to is far larger than that. For almost anything random in most games ever made, rand should do (except where knowing the prng would make it possible to cheat). I mean no human is able to tell the difference between a tic-tac-toe program using rand and one using something better.
The whole "real programmers use mersenne twister every time" notion that people occasionally like to boast, gets rather tiresome. It's purely premature optimisation.
People should learn that rand is far from a silver bullet as far as random number generators are concerned though.

If you're doing serious statistical work (or crypto work), you need a better source you can be sure of.

I can certainly agree with that. Hell I'd certainly prefer CryptGenRandom in such cases. It's all about knowing what tool is best for the job.

Okay this thread may be about something statistical, so perhaps mersenne twister would be appropriate.

Last edited by iMalc; 07-17-2008 at 02:19 AM.

My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger

Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"