Post on 18-Jan-2018
description
Pseudo-random-number generators
Random numbers: the numbers generated by a stochastic process
•They are indispensible in any simulations based on radom sampling.
•The „true” random numbers are obtained by hardware devices (the so-called random-noise generators). These are, however, expensive.
•However, by performing a sequence of algebraic operations on integer numbers, a sequence of numbers can be generated which are effectively random. Such numbers are referred to as pseudo-random numbers.
Linear Congruential Generators (LCG)
mcaxx jj mod1
A sequence of pseudo-random numbers generated by LCG has a period m, if and only if:
(a)c and m do not have common divisors.
(b)b=a-1 is a multiplicity of any primary number p, which is a divisor of m.
(c)b is a multiplicity of 4, if m also is a multiplicity of 4.
xi
xi+
1
m=7, a=3
The sequences of consecutive t pseudo-random numbers generated by MLCG form a regular t-dimensional lattice.
Example: t=2
m=97, a=29 m=97, a=23
ui
u i+1
ui
u i+1
mxu i
i
The uniform feature of the pseudo-random number distribution depends very strongly on the ratio of m do a
Conditions for uniformitydt – the largest distance between lattice nodes
21
873
7
121
6
103
541
461
3
41
2
1*
1
1
22364
22234
ccc
cccc
mcdd
md
md
tttt
tt
tt Almost uniform distribution
Significant deviation from the uniform distribution
Lower limits on the distance
Spectral test
65.0,
,*
amdmdamS
t
tt
Appropriate values of the modules m and multipliers a for transferable generators with the 32- and 16-bit arithmetics
32 bit 16 bitm a m a
2147483647 39373 32749 1622147483563 40014 32363 1572147483399 40692 32143 1602147482811 41546 32119 1722147482801 42024 31727 1462147483739 45742 31657 142
ui
u i+1
m=32749, a=162
Multiplicative linear congruent generators (MLCG)
Faster than te LCG generators but have a shorter period the number 0 cannot be obtained.
The rank of an MLCG generator: the smallest that satisfies the equation
a mod m = 1
The maximum period of a pseudo-random numbers generated by an MLCG is equal to the rank of that generator.
maxx jj mod1
A portable version of MLCG designed by Wichmann, Hill, and L’Ecuyer
mrqxqxamrqxqqxxa
mraqqxaxmmqxaxmax
raqmamramq
ma
mod])div()mod([mod])div(})div({[
mod)])(div([mod])div([mod][
mod,div
2
K=IX/IQ
IX=IA*(IX-K*IQ)-K*IR
IF (IX.LT.0) IX=IX+M
M=2147483563 IA=40014 IQ=53668 IR=12211
The VRND generator (based on the XOR operation) and RANDOMV (LCG).
The ran0, ran1 (shortest execution time), ran2 (optimally randomized numbers), ran3 (MLCG) generators from Numerical Recipes
Generation of real pseudo-random numbers
Best results are obtained if several MLCG generators are combined.
IEOR: bitwise exclusive OR
A 1 0 1 1 0 1 0 1B 1 1 0 1 1 1 0 1
IEOR(A,B) 0 1 1 0 1 0 0 0
Generation of non-uniformly distributed random numbers
1.By transformation of the uniform distribution.
2.By the von Neumann „hit-and-miss” method.
Uniform distribution transformationLet x be a random number normally distributed in [0,1]
1,0,0)(10,1)(
xxxf
xxf
A random number with distribution given by g(y) can then be computed from the inverse of the distribuand G(y) at x provided that G has the inverse:
)(
)()(
)()(
1 xGy
dttgyGx
ydGdyygdxy
Transormation of a random number x with a uniform distribution to random number y with distribund G(y) for continuous (a) and discrete (b) distributions.
Example: random number with exponential distribution
)1ln()(
)exp(1')'(1)(
0,0
0,exp1)(
1
0'
xxGt
tdttgtGx
t
tttg
t
t
An example of exponential distribution generation for various sampling sizes.
The von Neumann „hit-and-miss” method
x
f(x)
xminxmax
fmin
fmax
Rejected points
Accepted points
An efficient algorithm to generate normal distribution
1. Generate two pseudo-random numbers u1 i u2 from a uniform distribution in [0,1]. Compute v1=2u1-1 i v2=2u2-1.
2. Compute s=v12+v2
2.
3. If s>=1, go back to 1.
4. Compute
These numbers are drawn from a normal distrubition with 0 mean and unit variance.
To generate a multidimensional normal distribution, the Cholesky transfomation of the variance-covariance matrix is carried out first and then variables i=(LT(x-a))i are generated from normal distributions with zero mean and unit variance. These are subsequently transformed to the original variable space by applying the inverse transformation.
The gaussdev.f program from Numerical Recipes.
ssvxssvx ln2,ln2 2211