# random number algorithm (RNG) - pseudorandom

#### by Sanju 2010-01-25 11:48:23

A random number generator (RNG) is a computational or physical device designed to generate a sequence of numbers or symbols that lack any pattern...

A pseudorandom number generator (PRNG) is an algorithm used for generating a sequence of random numbers.

The 1997 invention of the Mersenne twister algorithm, by Makoto Matsumoto and Takuji Nishimura, avoids many of the problems with earlier generators.
It is now increasingly becoming the random number generator of choice..

Here is an simple example code of pseudo-random number generator. This is computationally fast and has good randomness properties
m_w = <choose-initializer>; /* must not be zero */
m_z = <choose-initializer>; /* must not be zero */

uint get_random()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}

A PRNG suitable for cryptographic applications is called a cryptographically secure PRNG (CSPRNG).

932
1
0