PRNG
PRNG
1
Random numbers on a computer
• Truly Random - the result of a physical process such as
timing clocks, circuit noise, Geiger counts, bad memory
– Too slow (we need 1010/sec) and expensive
– Low quality
– Not reproducible. But new INTEL chip does this for security
• Pseudo-random. prng (pseudo means fake)
– Deterministic sequence with a repeat period but with the
appearance of randomness (if you don’t know the
algorithm).
• Quasi-random (quasi means almost random)
– “half way” between random and a uniform grid.
– Meant to fill space with max. distance between space to fill
“holes” sequentially (e.g., [0,100] as 0,1,2,3,…,100).
2
Intel’s RNG: Ivy Bridge
• Article describing it: 3 Gbits/sec
• http://spectrum.ieee.org/computing/hardware/behind-intels-
new-randomnumber-generator/0
3
Desired Properties of RNG on a computer
• Uncorrelated Sequences:
<f1(xi+1)…fk(xi+k)>= <f1(xi+1)>…<fk(xi+k)>
Monte Carlo can be very sensitive to such
correlations, especially for large k.
4
Pseudo Random Sequence
5
Period or Cycle Length (L)
• If internal state has M bits, total state space is 2M values.
• If mapping is 1-1, space divides into a finite no. of cycles.
• Best case is a single cycle of length 2M, otherwise 2M/L.
• It is easy to achieve very long cycle length: 32 or 24 bit
generators are not long enough!
• Entire period of the RNG is exhausted in:
• rand (1 processor) ~ 100 second
• drand48 (1 processor) ~ 1 year
• drand48 (100 processor) ~ 3 days
• SPRNG LFG (105 procs) ~ 10375 years
Assuming 107 RN/sec per processor
• 48 bit LCG
zn = a*zn-1 + p vary p
• 64 bit LCG
• Prime Modulus LCG (modulo m )
vary a
Recurrence Parallelization
7
Uniformity
• Output consists of taking N bits from state and making
an integer in (0,2N-1) “Ik”.
8
Sequential RNG Problems
• Correlations non-uniformity in higher dimensions
13
SPRNG: originally a NCSA project
SPRNG Functions
• int *init_sprng(int streamnum, int nstreams, int seed, int param)
• double sprng(int *stream)
• int isprng(int *stream)
• int print_sprng(int *stream)
• int make_sprng_seed()
• int pack_sprng(int *stream, char **buffer)
• int *unpack_sprng(char *buffer)
• int free_sprng(int *stream)
• int spawn_sprng(int *stream, int nspawned, int ***newstreams)
14
What is a chisquare test?
• Suppose { x1,x2,….} are N Gaussian random numbers with
mean zero, and variance 1
N
• What is the distribution of y = ∑ x2 ?
k =1
• Q( χ | N )
2
is the probability that y>c2
χ =∑
2 k k
σ k2
k=1
GOOD BAD
16
See “Numerical Recipes” on reserve or on-line
(link on class webpages)
(N i − ni )2
• Chi-squared statistic is χ = ∑i
2
ni
– ni (Ni) is the expected (observed) number in bin i.
– Ni is an integer! (Omit terms with 0 = ni = Ni)
– Term with ni = 0 and Ni ≠ 0, correctly give χ2 = ∞.)
– Large values of χ2 indicate the “null” hypothesis, i.e. unlikely.
Probability Interpretation
<1% reject
1-5% suspect
5 - 10 % almost suspect
10 - 90 % pass
90 - 95 % almost suspect
95 - 99 % suspect
17
> 99 % reject
Recommendation:
For careful work use several generators!
• For most real-life MC simulations, passing existing
statistical tests is necessary but not sufficient.
18
Parallel Simulations
• Problems:
– Big systems require excessive wall clock time.
– Excessive amounts of output data generated.
– Random number correlation?
20
Parallelization of RNGs
21
Examples of Parallel MC codes and Problems
23