Random Number Generation (RNG) Pembangkitan Bilangan Random Random Number Generation 1
Definition of RNG RNG suatu algoritma yg digunakan utk menghasilkan urutan angka2 sbg hasil perhitungan dgn komp., yg diketahui distribusinya shg angka2 tsb muncul sec. random & digunakan terus-menerus Sequence/urutan Distribusi Munculnya angka2 secara random Umumnya default: distribusi uniform Random Number Generation 2
Applications of RNG in gambling, statistical sampling, computer simulation, cryptography, completely randomized design, and other areas where producing an unpredictable result is desirable. Random Number Generation 3
Applications of RNG In general, where unpredictability is paramount such as in security applications hardware generators are generally preferred. RNG are very useful in developing Monte Carlo method simulations as debugging is facilitated by the ability to run the same sequence of random numbers again by starting from the same random seed. They are also used in cryptography so long as the seed is secret. Sender and receiver can generate the same set of numbers automatically to use as keys. Random Number Generation 4
Description of random number Dapat dinyatakan dalam: Table random number Electronic random number Congruential pseudo random number Yang sering digunakan Random Number Generation 5
Pseudo RNG (PRNG) A PRNG also known as a deterministic random bit generator (DRBG), is an algorithm for generating a sequence of numbers that approximates the properties of random numbers. Random Number Generation 6
Pseudo RNG (PRNG) The generation of pseudo-random numbers is an important and common task in computer programming. Uses computational algorithms that produce long sequences of apparently random results, It is determined by a shorter initial value known as a seed or key Random Number Generation 7
Pseudo RNG (PRNG) One of the most common PRNG is the linear congruential generator, which uses the recurrence : X Additive/arithmatic = ( a * X + b ) mod m n+ 1 n + PRNG 1 X: random number; a: koefisien; b: konstanta; m: modulo. Lebih besar dari m Bernilai ganjil bila m bernilai pangkat dua, & bukan kelipatan m Note: pemilihanx 0 adalah: integer, ganjil, cukup besar Random Number Generation 8
The other kinds of PRNG Multiplicative PRNG X n a +1 = ( * X n ) mod m 2 Random Number Generation 9
Random Number Generation Desirable Attributes: Uniformity Independence Efficiency Replicability Long Cycle Length Random Number Generation 10
Random Number Generation (cont.) Each random number R t is an independent sample drawn from a continuous uniform distribution between 0 and 1 1, 0 x 1 pdf: f(x) = 0, otherwise Random Number Generation 11
Techniques for Generating Random Number MidSquare Example: X 0 = 7182 (seed) 2 X 0 = 51581124 ==> R 1 = 0.5811 2 X = (5811) 2 0 = 33767721 ==> R 2 = 0.7677 etc. Random Number Generation 12
Techniques for Generating Random Number (cont.) Note: Cannot choose a seed that guarantees that the sequence will not degenerate and will have a long period. Also, zeros, once they appear, are carried in subsequent numbers. 2 Ex1: X 0 = 5197 (seed) = 27008809 0 X 0 2 X 1 ==> R 1 = 0.0088 = 00007744 ==> R 2 = 0.0077 2 Ex2: X 0 = 4500 (seed) = 20250000 2 ==> R 1 = 0.2500 = 06250000 ==> R 2 = 0.2500 X 0 X 1 Random Number Generation 13
Techniques for Generating Random Number (cont.) Multiplicative Congruential Method: Basic Relationship X i+1 = a X i (mod m), where a 0 and m 0 Most natural choice for m is one that equals to the capacity of a computer word. m = 2 b (binary machine), where b is the number of bits in the computer word. m = 10 d (decimal machine), where d is the number of digits in the computer word. Random Number Generation 14
Techniques for Generating Random The max period(p) is: Number (cont.) For m a power of 2, say m = 2 b, and c 0, the longest possible period is P = m = 2 b, which is achieved provided that c is relatively prime to m (that is, the greatest common factor of c and m is 1), and a = 1 + 4k, where k is an integer. For m a power of 2, say m = 2 b, and c = 0, the longest possible period is P = m / 4 = 2 b-2, which is achieved provided that the seed X 0 is odd and the multiplier, a, is given by a = 3 + 8k or a = 5 + 8k, for some k = 0, 1,... Random Number Generation 15
Techniques for Generating Random Number (cont.) For m a prime number and c = 0, the longest possible period is P = m - 1, which is achieved provided that the multiplier, a, has the property that the smallest integer k such that a k - 1 is divisible by m is k = m - 1, Random Number Generation 16
Techniques for Generating Random Number (cont.) (Example 1) Using the multiplicative congruential method, find the period of the generator for a = 13, m = 2 6, and X 0 = 1, 2, 3, and 4. The solution is given in next slide. When the seed is 1 and 3, the sequence has period 16. However, a period of length eight is achieved when the seed is 2 and a period of length four occurs when the seed is 4. Random Number Generation 17
Techniques for Generating Random Number (cont.) Period Determination Using Various seeds i X i X i X i X i 0 1 2 3 4 1 13 26 39 52 2 41 18 59 36 3 21 42 63 20 4 17 34 51 4 5 29 58 23 6 57 50 43 7 37 10 47 8 33 2 35 9 45 7 10 9 27 11 53 31 12 49 19 13 61 55 14 25 11 15 5 15 16 1 3 Random Number Generation 18
Techniques for Generating Random Number (cont.) Linear Congruential Method: X i+1 = (ax i + c) mod m, i = 0, 1, 2... (Example 2) let X 0 = 27, a = 17, c = 43, and m = 100, then X 1 = (17*27 + 43) mod 100 = 2 R 1 = 2 / 100 = 0.02 X 2 = (17*2 + 43) mod 100 = 77 R 2 = 77 / 100 = 0.77... Random Number Generation 19
Exercises/Tugas1 1. Diketahuix 0 = 12357, a = 197, m = 1387, danb= 2357. Uraikan sec. berurut utk mendapatkan bil. Random sebanyak 10 kali, dgn menggunakan arithmetic PRNG. 2. Diketahuix 0 = 12357, a = 197, m = 1387. Uraikan sec. berurut utk mendapatkan bil. Random sebanyak 10 kali, dgn menggunakan muliplicative PRNG. 3. Untuk Example 1 di atas, uraikan bilax 0 yang bernilai lainnya, silahkan ditentukan sendiri nilaix 0 tersebut dan bagaimana pengulangan data random semunya. 4. Untuk example 2, lanjutkan dengan perhitungan pembangkitan random berikutnya misal sampai dengan 100 kali pembangkitan (gunakan excel). Apakah data pembangkitan random semu tersebut muncul antara 0 dan 1. Random Number Generation 20
References Herman D. Hughes, CSE808 Modeling and Discrete Simulation, Michigan State University, Fall 2003 Tri Harsono, Materi Ajar Modeling and Simulation, PENS, 2013 Random Number Generation 21