2. • Random number yang digunakan dalam simulasi adalah Random
number yang berbasis pada bilangan kontinyu antara 0 sampai 1,
dimana peluang untuk terpilihnya suatu bilangan adalah sama.
• Dalam teori distribusi probabilitas, hal tersebut dapat ditemukan
pada distribusi uniform dengan a=0 dan b=1.
• Uniform (0,1) ini akan digunakan sebagai GENERATOR UTAMA dalam
membangkitkan bilangan random yang berdistribusi selain U(0,1).
Random number generators
3. Random number generators
A ‘good’ random-number generator should satisfy the following properties:
• Uniformity: The numbers generated appear to be distributed uniformly on
(0, 1)
• Independence: The numbers generated show no correlation with each
other
• Replication: The numbers should be replicable (e.g., for debugging or
comparison of different systems)
• Cycle length: It should take long before numbers start to repeat
• Speed: The generator should be fast
• Memory usage: The generator should not require a lot of storage.
6. Random number generators
Most random-number generators are of the form:
• Start with 𝑧0 (seed)
• For n=1,2, … generate:
𝑧𝑛 = 𝑓(𝑧𝑛−1)
and
𝑢𝑛 = 𝑔(𝑧𝑛)
f is the pseudo-random generator
g is the output function
{𝑢0, 𝑢1, … } is the sequence of uniform random numbers on the interval (0,1)
8. Middle square
STEPS:
• Start with a 4-digit number 𝑧0 (seed)
• Square it to obtain 8-digits (𝑧0
2
) (if necessary, append zeros to the left)
• Take the middle 4 digits of 𝑧0
2
to obtain the next 4-digit number 𝑧1
• We get uniform random (𝑢1)number by placing the decimal point at
the left of each 𝑧1 (i.e., divide by 10000)
• And so on.
9. Example
9
i Zi Ui (Zi)2
0 7182 - 51581124
1 5811 0.5811 33767721
2 7677 0.7677 58936329
3 9363 0.9363 87665767
10. Practical way
Supaya nilai U antara 0 dan 1, maka:
nilai maksimalsesuai digit
i
i
Z
U
Misalkan digit=2, maka nilai maksimalnya 99
Misalkan digit=3, maka nilai maksimalnya 999
Misalkan digit=4, maka nilai maksimalnya 9999
dst
12. Linear congruential generators
• Most random-number generators in use today are linear congruential
generators.
• They produce a sequence of integers between 0 and m-1 according
to:
a is the multiplier (0 < a < m), c the increment (0 <= c < m) and m the
modulus (m > 0), with Z0 is seed or starting value (0 <= Z0 < m)
• To obtain uniform random numbers on (0,1) we take
• A good choice of a, c and m is very important.
1
( ) mod
n n
x ax c m
𝑢𝑛 =
𝑧𝑛
𝑚
13. Linear congruential generators
Example:
• For (a, c, m) = (1, 5, 13) and x0 = 1 we get the sequence x1, …, xn are
1, 6, 11, 3, 8, 0, 5, 10, 2, 7, 12, 4, 9, 1, … which has full period (of 13).
• For (a, c, m) = (2, 5, 13) and x0=1 we get the sequence x1, …, xn are 1,
7, 6, 4, 0, 5, 2, 9, 10, 12, 3, 11, 1, … which has a period of 12. If we
take x0 = 8, we get the sequence 8, 8, 8, … (period of 1).
14. When c > 0.
Guidance to choose a, c, m, X0 :
• Nilai konstanta a > akar m
• Konstanta c harus berangka ganjil apabila m bernilai
pangkat dua. Nilai c bukan kelipatan m
• Modulo m adalah bilangan prima.
• Nilai x0 bernilai integer, ganjil , dan besar
Additive congruential generator
15. Multiplicative congruential generator
These generators produce a sequence of integers between 0 and m-1
according to:
𝑥𝑛= a𝑥𝑛−1 mod 𝑚
So they are linear congruential generators with c = 0.
They cannot have full period, but it is possible to obtain period m-1 (so
each integer 1, ..., m-1 is obtained exactly once in each cycle) if a and m
are chosen carefully.
16. Guidance to choose a, m, x0 :
• Nilai a adalah bilangan prima.
• Nilai m adalah integer dan besar.
• Nilai x0 (disebut seed) integer, ganjil, dan besar
Multiplicative congruential generator