You are on page 1of 3

Random number generation (Chapter-7)

Ques: Write down the techniques of generating random number


Ans: There are three techniques of generating random numbers
1. Linear congruential method
2. Combined linear congruential method
3. Random-number streams
Ques: Write down the definition of linear congruential method
Ans: The linear congruential method produces a sequence of integers X1, X2 ,…………. Between zero
and m-1 by following a recursive relationship.
Xi+1= (aXi + c) mod m, i =0,1,2………
The initial value Xo is called the seed, a is called multiplier, c is increment and m is modulus. If c ≠0
,then the form is called the mixed congruential method. When c=0 then the form is known as the
multiplicative congruential method.

Example 7.1
Use the linear congruential method to generate a sequence of random numbers with X0=27, a=17,
c=43 and m=100.
Ans : we kmow,
𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚
𝑋0+1 = (𝑎𝑋0 + 𝑐) 𝑚𝑜𝑑 𝑚
𝑋1 = (17 × 27 + 43)𝑚𝑜𝑑 100
= 402 𝑚𝑜𝑑 100 = 2
100|402|4
400
2
𝑋2 = (17 × 2 + 43)𝑚𝑜𝑑 100
𝑋2 = 77 𝑚𝑜𝑑 100 = 𝟕𝟕
𝑋3 = (17 × 77 + 43)𝑚𝑜𝑑 100
𝑋3 = 1352 𝑚𝑜𝑑 100 = 𝟓𝟐
𝑋4 = (17 × 52 + 43)𝑚𝑜𝑑 100
𝑋4 = 927 𝑚𝑜𝑑 100 = 𝟐𝟕
Ques: Use the linear congruential method to generate a sequence of random numbers with
X0=27, a=17, c=43 and m=100.
Generate random number between 0 and 1
Ans: Random numbers between zero and 1 can be generated by
𝑋𝑖
𝑅𝑖 = , 𝑖 = 1,2,3 … ….
m

𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚


𝑋0+1 = (𝑎𝑋0 + 𝑐) 𝑚𝑜𝑑 𝑚
𝑋1 = (17 × 27 + 43)𝑚𝑜𝑑 100
= 402 𝑚𝑜𝑑 100 = 2
𝑋1 2
𝑅1 = = = 𝟎. 𝟎𝟐
100 100
𝑋2 = (17 × 2 + 43)𝑚𝑜𝑑 100
𝑋2 = 77 𝑚𝑜𝑑 100 = 𝟕𝟕
𝑋2 77
𝑅2 = = = 𝟎. 𝟕𝟕
100 100
𝑋3 = (17 × 77 + 43)𝑚𝑜𝑑 100
𝑋3 = 1352 𝑚𝑜𝑑 100 = 𝟓𝟐
𝑋3 52
𝑅3 = = = 𝟎. 𝟓𝟐
100 100
Ques: Use the linear congruential method to generate a sequence of random numbers between 0 and 24
with X0=13, a=9, c=35 .
Ans: mod m= 24+1= 25
𝑋𝑖+1 = (𝑎𝑋𝑖 + 𝑐) 𝑚𝑜𝑑 𝑚
𝑋0+1 = (𝑎𝑋0 + 𝑐) 𝑚𝑜𝑑 𝑚
𝑋1 = (9 × 13 + 35)𝑚𝑜𝑑 25
= 152 𝑚𝑜𝑑 25 = 2
𝑋2 = (9 × 2 + 35)𝑚𝑜𝑑 25
= 53 𝑚𝑜𝑑 25 = 3
𝑋3 = (9 × 3 + 35)𝑚𝑜𝑑 25
= 62 𝑚𝑜𝑑 25 = 12
𝑋4 = (9 × 12 + 35)𝑚𝑜𝑑 25
= 143 𝑚𝑜𝑑 25 = 18
𝑋5 = (9 × 18 + 35)𝑚𝑜𝑑 25
= 197 𝑚𝑜𝑑 25 = 22
We got three random number between 0 and 24 is 12 , 18 and 22 Ans

You might also like