Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pseudo-random number generator

What is the best way to create the best pseudo-random number generator? (any language works)

like image 240
Phantom73 Avatar asked Feb 25 '09 03:02

Phantom73


2 Answers

Best way to create one is to not to.

Pseudo-random number generators are a very complex subject, so it's better off to use the implementations produced by the people that have a good understanding of the subject.

like image 175
coobird Avatar answered Oct 04 '22 02:10

coobird


It all depends on the application. The generator that creates the "most random" numbers might not be the fastest or most memory-efficient one, for example.

The Mersenne Twister algorithm is a popular, fairly fast pseudo-random number generator that produces quite good results. It has a humongously large period, but also a relatively humongous state (2.5 kB). However it is not deemed good enough for cryptographic applications.

Update: Since this answer was written, the PCG family of algorithms was published that seems to outperform existing non-cryptographic algorithms on most fronts (speed, memory, randomness and period), making it an excellent all-round choice for anything but cryptography.

If you're doing crypto though, my answer remains: don't roll your own.

like image 21
Thomas Avatar answered Oct 04 '22 02:10

Thomas