Pseudorandom number generators (or PRNGs for short) are basically programs or algorithms which, given a seed value, will output a sequence of pseudorandom numbers. In computer simulations and cryptography having a reliable stream of random data is often necessary.

However, because computers are deterministic machines (at least when they're not going wrong and their CPUs aren't overheating) they can't actually generate true random numbers, hence the usage of algorithms to create their 'random numbers'. Most algorithms which do this are fairly simple, but not all are cryptographically secure, or fast. Most, however, are OK for simple purposes (like die throwing).

Before you can use a PRNG, you must seed it. Seeding is the technical term for giving it an initial value, from which it can shoot out a sequence. If you give a PRNG the same seed, then it will give you the same set of numbers every time. Hence picking your seed is important. If a PRNG doesn't ask for a seed, then it may well take a seed itself from the system timer or something else.

Even without using the same seed each time, PRNGs can still run into problems; every PRNG has a period which is how many numbers it outputs before it repeats itself. For the simplest PRNG, this might be maybe a dozen hundred numbers or so, and this is fine for computer games, but not so good for simulations which iterate a few thousand times over. The best PRNGs have periods of the order of 1050 or thereabouts.

Recently, however, people have started to use random seeds for PRNGs, such as from radioactive atoms decaying1 or lavalamps.2 Some have even just taken random data and converted it to binary to make random 0s and 1s.

Here's some other nodes on PRNGs:

Here's some PRNG algorithms:

There are already nodes about this, but I don't think any of them cover all aspects of PRNGs individually. So I figured I might as well collate the data.

1 When a bunch of radioactive atoms decay, you can predict roughly how many will decay, but not whether or not a particular atom will - just its probability of doing so.
2N-Wing says: "re Pseudorandom number generator : I believe Intel (and maybe others) have something in their chips now that give truely random numbers (some sensor measures something). I'm not sure, though. (I glanced over something on Intel's site that mentioned that.)

The contents of this writeup are in the public domain.

Log in or register to write something here or to contact authors.