Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator.

Similar presentations


Presentation on theme: "1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator."— Presentation transcript:

1 1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator (LCG) u Explicit Inversive Congruential Generator u Non-linear Additive Feedback u Transform-Expand-Sample (TES) –Technical issues for RNGs u Testing RNGs

2 2 Motivation H Many simulations rely on use of random number generators (RNG) H Want to assess the “typical” behaviour of a system, and its average case perf H Single simulation run: one answer H Multiple runs: lots of (different) answers! H Central Limit Theorem: convergence to Normal distribution, with well-defined mean and variance (confidence intervals)

3 3 RNG Details H Truly random RNGs are hard to find H We settle for pseudo-random RNG H Assumes we can find “good” pseudo- random number generators H Assumes proper seeding of pseudo-RNG H Basic building block: U(0,1) H All other distributions can be generated from this using inverse mapping of CDF

4 4 Inverse Mapping (1 of 2) H If you have y = U(0,1), then you can generate x from any other distribution using inverse transformation (mapping) H Uses Cumulative Distribution Function (CDF) of the desired distribution H y = F(x) H x = F -1 (y) H Can be analytic formula or empirical data

5 5 Inverse Mapping (2 of 2) 0 x y 1 y = F(x) F(x) y1y1 y2y2 x1x1 x2x2

6 6 RNG Requirements H Uniformly distributed H Uncorrelated H Reproducible H Portable H Long Period H Analyzable H Computationally fast H Parallelizable H Scales suitably to any number of processors H Uncorrelated streams H Independent generation H Easy to use (API) H Gives right results!

7 7 LCG Basics H The most prevalent type of pRNG is the Linear Congruential Generator (LCG) H Formally a 4-tuple: LCG(m, a, b, y 0 ) with modulus m, multiplier a, offset b, and initial seed y 0 H Formula: y n+1 = (a y n + b) mod m H Generates pRN series in {0…m-1} H Can normalize to U(0,1) by dividing by m

8 8 LCG: Toy Example H Example: a=12, b=5, m=57, y 0 = 34 H Sequence: –34, 14, 2, 29, 11, 23, 53, 14, 2, 29, 11,... H Note the short cycle with period < m H In practice, want m large, and a, b, y 0 carefully chosen so that period is large H Some very good values are known

9 9 EICG H Another type is the Explicit Inversive Congruential Generator (EICG) H Also a 4-tuple: EICG(m, a, b, n 0 ) H Formula: y n = (an + b) mod m H Note the inversion modulo m

10 10 Some Typical RNGs H rand() 32-bit multiplicative CG H random() 32-bit non-linear additive FB H drand48() 48-bit LCG H erand48() 48-bit LCG H Some are better than others H Don’t forget to seed them properly!

11 11 RNG Testing H How to test the goodness of a RNG? H Large samples H Bucket analysis (uniformity test) H Auto-correlation analysis (second-order) H d-dimensional plots H Spectral tests H Discrepancy tests H Kolmogorov-Smirnov (KS) tests

12 12 RNG Issues H Size of stream used vs. generation period H General safety rule: square root H Want independent streams for each RV H How to generate for parallel/distributed –Splitting into non-overlapping blocks –Leap-frog technique p1p2p3p4 pipi pjpj

13 13 Transform-Expand-Sample (TES) H What if you want correlated RNs? H Use TES! H Map U(0,1) to unit circle (modulo 1) H Constrain location of subsequent points H Multiple constraints 01 0

14 14 Summary H Random number generation is at the heart of almost any computer simulation H Quality of the pRNG is very important (and often overlooked!) H Using RNG properly is important H Seeding them properly is important too H Statistical inference from simulation results only makes sense if RNG works


Download ppt "1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator."

Similar presentations


Ads by Google