Random - Number Generators
Random - Number Generators
1
Random Number Generators
Random number generation is a method of producing a sequence
of numbers that lack any discernible pattern.
2
What is Random?
What do we mean by Random?
•Uncorrelated (with what you're interested in)
•Quantum systems are truly random (we believe)
•Some times we want repeatability from a random number
generator.
3
Pseudo RNGs
The pseudo means false.
Pseudo implies that the random numbers are generated by
using some known arithmetic operation.
Since, the arithmetic operation is known and the sequence of
random numbers can be repeated obtained, the numbers
cannot be called truly random.
However, the pseudo random numbers generated by many
computer routines , very closely fulfill the requirement of
desired randomness.
4
Pseudo RNGs
5
Pseudo RNGs
PRNGs usually generate very long sequences of random numbers.
For example the commonly used Mersenne Twister MT19937 has a
sequence length of 219937-1.
6
Pseudo RNGs
While long sequence length is a good property of a PRNG, it is not
sufficient to ensure that the numbers generated are random.
7
Bit Properties
Ideally a generator will produce numbers that are made up of
completely random bits.
8
Generator Algorithms
Computer systems often come supplied with a RNG built in.
eg rand() or random()
While these are fast and easy to use, they may not be very random,
have short repeat sequences and may have strong correlation
patterns.
9
Linear Congruential Generator
Many built-in RNGs use the Linear Congruential Generator or LCG.
This generator is very fast, has low memory requirements but for
most serious applications where randomness actually matters, it is
useless.
10
Linear Congruential Generator
A sequence of random values Xn where:
Xn+1 = ( a Xn + c ) mod m
with well-chosen values of a, c, m
11
Linear Congruential Generator
Example Sequences:
m=10, a=1, c=7
m=10, a=2, c=1
1
X0=1
8 (1*1 + 7 % 10)
3 (2*1 + 1) % 10
5 (1*8 + 7 % 10)
7 (2*3 + 1 )% 10
2 (1*5 + 7 % 10)
5 (2*7 + 1 )% 10
9 (1*2 + 7 % 10)
1 (2*5 + 1 )% 10
6 (1*9 + 7 % 10)
3 (2*1 + 1 )% 10
3 (1*6 + 7 % 10)
7 (2*3 + 1 )% 10
0 (1*3 + 7 % 10)
5 (2*7 + 1 )% 10
…
… 12
Linear Congruential Generator
13
• Numerical Recipes is the generic title of a series of books on algorithms and numerical
analysis by William H. Press, Saul A. Teukolsky, William T. Vetterling and Brian P.
Flannery. In various editions, the books have been in print since 1986. The most
recent edition was published in 2007.
• GNU Compiler Collection (GCC) is a compiler system produced by the GNU
Project supporting various programming languages. GCC is a key component of the GNU
toolchain and the standard compiler for most projects related to GNU and Linux, the
most notable is the Linux kernel. The Free Software Foundation (FSF) distributes GCC
under the GNU General Public License (GNU GPL). GCC has played an important role in
the growth of free software, as both a tool and an example.
• MMIX (pronounced em-mix) is a 64-bit reduced instruction set
computing (RISC) architecture designed by Donald Knuth, with significant contributions
by John L. Hennessy (who contributed to the design of the MIPS architecture) and
Richard L. Sites (who was an architect of the Alpha architecture)
14
Linear Congruential Generator
Various sources use different parameters for the LCG:
Numerical Recipes
m = 232 a = 1664525 c = 1013904223
GCC
m = 232 a = 1103515245 c = 12345
MMIX
m = 264 a = 6364136223846793005 c = 1442695040888963407
15
Mid Square Method
16
Ex1: X0 = 5197 (seed) = 27008809
==> R1 = 0.0088 = 00007744
==> R2 = 0.0077
17
Lagged Fibonacci Generator
The Lagged Fibonacci Generator is based on a generalisation of the
Fibonacci sequence
1, 1, 2, 3, 5, 8, 13, 21 ....
Xn = Xn-1 + Xn-2
18
Lagged Fibonacci Generator
The LFG generator is defined by:
19
Mersenne Twister
The Mersenne Twister is a widely used PRNG, the name comes
from the period length which is chosen to be a Mersenne Prime.
See:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
20
Distributions
PRNGs usually produce random unsigned integers which can easily
be converted to a uniform distribution [0,1).
21
Software Practicalities
Applications that require high quality random number generators
often require a large number of them.
22
Software Practicalities
What type of data primitives does the generator use?
23
Software Practicalities
How much storage does the PRNG require?
24
Software Practicalities
How dependent is the generator on the initialisation?
How can we generate a random initial state that will still produce
high-quality random numbers?
25
Truly Random Numbers
While most computers are incapable of producing truly random
numbers there are some modern devices capable of generating a
truly random number.
26
Truly Random Numbers
The Quantis card is a physical random number generator that
exploits a quantum optics process.
Truly Random Numbers
A simulation that uses a truly random number is not repeatable.
The craps test: play 200,000 games of craps, counting the wins and
number of throws per game. Each count should follow a given
distribution.
Diehard Tests
Overlapping permutations test: