11
Discrete Distributions
Discrete uniform
Bernoulli
Binomial
Geometric
Negative binomial
Poisson
12
Bagaimana Cara membangkitkan Bilangan
Acak?
Distribusi
Uniform
Bagaimana membangkitkan bilangan acak?
Perilaku acak (random behavior) ditiru oleh simulasi
dengan menggunakan pembangkit bilangan acak
(random number generator)
Bilangan-bilangan yang dihasilkan oleh pembangkit
bilangan acak tidak “acak” dalam arti yang
sebenarnya. Contohnya pembangkit bilangan acak
pseudo, yang terus menerus menghasilkan urutan
bilangan yang sama
LCG (linear congruential generator)
Metoda yang paling umum untuk membangkitkan bilangan acak
Sebuah urutan bilangan integer Z1, Z2, Z3, … didefinisikan dengan
formula rekursif sbb:
a : multiplier
c : increment
m: panjang siklus maksimum
Dimana a, c, m > 0 dan integer
c and m tidak punya nilai FPB selain 1
a = 1 + 4k, where k is an integer.
Nilai m=2b
Seed value Zo, 0<Zo<m-1
Nilai random : Ui=Zi/m
Contoh LCG
a=21, c=3, m=16 untuk menghasilkan angka acak –
pseudo (pseudo-random numbers)
Zi = (aZi-1 + c) mod(m) Zi = (21Zi-1+ 3) mod (16)
Z0 = 13 (Pilih angka antara 0 dan 15 (m-1)) seed
value, starting value . (0<Zo<m-1)
Z1 = (21Z0 + 3) mod (16) = (21(13)+3) mod (16)
=276 mod (16) = 4
Ui = Zi/16 = 4/16 = 0.2500
Ui=Zi/m
Contoh LCG
i Zi Ui = Zi/m
0 13 a 21
1 276 4 0.25 c 3
2 87 7 0.4375 m 16
3 150 6 0.375
4 129 1 0.0625
5 24 8 0.5
6 171 11 0.6875
7 234 10 0.625
8 213 5 0.3125
9 108 12 0.75
10 255 15 0.9375
11 318 14 0.875
12 297 9 0.5625
13 192 0 0
14 3 3 0.1875
15 66 2 0.125
16 45 13 0.8125
17 276 4 0.25
18 87 7 0.4375
19 150 6 0.375
20 129 1 0.0625
LCG
Nilai maksimum yang dapat dibangkitkan dari sebuah
LCG adalah m
Petunjuk untuk menentukan a, c, dan m (Pritsker,
1995)
m = 2b where b is determined based on the number of
bits per word on the computer being used (for computer
with 32 bits, b = 31)
c and m such that their greatest common factor is 1.
a = 1 + 4k, where k is an integer.
output bits of seed
Source m (multiplier) a (increment) c
in rand() /Random(L)
Numerical Recipes 232 1664525 1013904223
bits 30..16 in rand(), 30..0
Borland C/C++ 232 22695477 1
in lrand()
glibc (used by GCC)[5] 231 1103515245 12345 bits 30..0
ANSI C: Watcom,
Digital Mars, CodeWarrior 231 1103515245 12345 bits 30..16
, IBM VisualAgeC/C++ [6]
C99, C11: Suggestion in
232 1103515245 12345 bits 30..16
the ISO/IEC 9899 [7]
Borland Delphi,
232 134775813 1 bits 63..32 of (seed * L)
Virtual Pascal
Apple CarbonLib, C++11
231 − 1 16807 0 see MINSTD
's minstd_rand0[10]
Xi=-ϐln(1-Ui)
Service time ~ exponential distribution with mean = 2.4 minutes.
0 3 122
1 66 0,516 2,17 5 0,039 0,10 1 2,17 2,17 0,10 2,27 0,00 0,10
2 109 0,852 5,72 108 0,844 4,46 2 7,90 7,90 4,46 12,35 0,00 4,46
3 116 0,906 7,10 95 0,742 3,25 3 15,00 15,00 3,25 18,25 0,00 3,25
4 7 0,055 0,17 78 0,609 2,26 4 15,17 18,25 2,26 20,51 3,08 5,34
5 22 0,172 0,57 105 0,820 4,12 5 15,73 20,51 4,12 24,63 4,77 8,89
6 81 0,633 3,01 32 0,250 0,69 6 18,74 24,63 0,69 25,32 5,89 6,58
7 40 0,313 1,12 35 0,273 0,77 7 19,86 25,32 0,77 26,08 5,46 6,22
8 75 0,586 2,65 98 0,766 3,48 8 22,51 26,08 3,48 29,57 3,58 7,06
9 42 0,328 1,19 13 0,102 0,26 9 23,70 29,57 0,26 29,82 5,87 6,12
10 117 0,914 7,36 20 0,156 0,41 10 31,06 31,06 0,41 31,47 0,00 0,41
11 28 0,219 0,74 39 0,305 0,87 11 31,80 31,80 0,87 32,68 0,00 0,87
12 79 0,617 2,88 54 0,422 1,32 12 34,68 34,68 1,32 36,00 0,00 1,32
13 126 0,984 12,48 113 0,883 5,15 13 47,16 47,16 5,15 52,31 0,00 5,15
14 89 0,695 3,57 72 0,563 1,98 14 50,73 52,31 1,98 54,29 1,58 3,56
15 80 0,625 2,94 107 0,836 4,34 15 53,67 54,29 4,34 58,63 0,62 4,96
16 19 0,148 0,48 74 0,578 2,07 16 54,15 58,63 2,07 60,70 4,48 6,55
17 18 0,141 0,45 21 0,164 0,43 17 54,61 60,70 0,43 61,13 6,09 6,52
18 125 0,977 11,26 60 0,469 1,52 18 65,87 65,87 1,52 67,38 0,00 1,52
19 68 0,531 2,27 111 0,867 4,85 19 68,14 68,14 4,85 72,98 0,00 4,85
20 23 0,180 0,59 30 0,234 0,64 20 68,73 72,98 0,64 73,63 4,25 4,89
21 102 0,797 4,78 121 0,945 6,97 21 73,52 73,63 6,97 80,60 0,11 7,08
22 97 0,758 4,25 112 0,875 4,99 22 77,77 80,60 4,99 85,59 2,83 7,82
23 120 0,938 8,32 51 0,398 1,22 23 86,09 86,09 1,22 87,31 0,00 1,22
24 91 0,711 3,72 50 0,391 1,19 24 89,81 89,81 1,19 91,00 0,00 1,19
25 122 0,953 9,18 29 0,227 0,62 25 98,99 98,99 0,62 99,61 0,00 0,62
0 29 92
1 100 0,781 4,56 15 0,117 0,30 1 4,56 4,56 0,30 4,86 0,00 0,30
2 55 0,430 1,68 62 0,484 1,59 2 6,24 6,24 1,59 7,83 0,00 1,59
3 6 0,047 0,14 25 0,195 0,52 3 6,39 7,83 0,52 8,36 1,45 1,97
4 1 0,008 0,02 16 0,125 0,32 4 6,41 8,36 0,32 8,68 1,94 2,26
5 24 0,188 0,62 83 0,648 2,51 5 7,03 8,68 2,51 11,18 1,64 4,15
6 123 0,961 9,73 82 0,641 2,46 6 16,76 16,76 2,46 19,22 0,00 2,46
7 26 0,203 0,68 61 0,477 1,55 7 17,44 19,22 1,55 20,77 1,77 3,33
8 37 0,289 1,02 4 0,031 0,08 8 18,47 20,77 0,08 20,85 2,31 2,38
9 12 0,094 0,30 87 0,680 2,73 9 18,76 20,85 2,73 23,58 2,09 4,82
10 127 0,992 14,56 38 0,297 0,85 10 33,32 33,32 0,85 34,16 0,00 0,85
11 110 0,859 5,88 33 0,258 0,72 11 39,20 39,20 0,72 39,92 0,00 0,72
12 9 0,070 0,22 56 0,438 1,38 12 39,42 39,92 1,38 41,30 0,50 1,88
13 64 0,500 2,08 27 0,211 0,57 13 41,50 41,50 0,57 42,07 0,00 0,57
14 67 0,523 2,22 58 0,453 1,45 14 43,73 43,73 1,45 45,17 0,00 1,45
15 2 0,016 0,05 69 0,539 1,86 15 43,77 45,17 1,86 47,03 1,40 3,26
16 45 0,352 1,30 44 0,344 1,01 16 45,07 47,03 1,01 48,04 1,96 2,97
17 52 0,406 1,56 31 0,242 0,67 17 46,64 48,04 0,67 48,71 1,41 2,07
18 71 0,555 2,43 14 0,109 0,28 18 49,06 49,06 0,28 49,34 0,00 0,28
19 86 0,672 3,34 41 0,320 0,93 19 52,41 52,41 0,93 53,33 0,00 0,93
20 17 0,133 0,43 96 0,750 3,33 20 52,83 53,33 3,33 56,66 0,50 3,83
21 104 0,813 5,02 99 0,773 3,56 21 57,86 57,86 3,56 61,42 0,00 3,56
22 11 0,086 0,27 34 0,266 0,74 22 58,12 61,42 0,74 62,16 3,29 4,03
23 106 0,828 5,28 77 0,602 2,21 23 63,41 63,41 2,21 65,62 0,00 2,21
24 53 0,414 1,60 84 0,656 2,56 24 65,01 65,62 2,56 68,18 0,60 3,17
25 92 0,719 3,81 103 0,805 3,92 25 68,82 68,82 3,92 72,74 0,00 3,92