Congruential Algorithms
Congruential Algorithms
[Link] algorithm
This congruential algorithm was proposed by D. H. Lehmer in 1951. According to
Law y
Kelton has not been the most used. The linear congruential algorithm generates a
sequence of integers through the following recursive equation:
where Xis0 the seed, aes is the multiplicative constant, ces is a constant
additive, and you put the module.0> 0,
X a > 0, c > 0 and m > 0 must be integers.
The operation 'mod (m)' means to multiply, add c,Xand i divide the
X
result between to obtain the remainderi +1It is important to note that the
the recursive equation of the linear congruential algorithm generates a sequence of
integer numbers S = {0, 1, 2, 3, ..., m - 1}, and that to obtain numbers
pseudo-random in the interval (0, 1The following equation is required:
XI
r i= i=0 , 1 , 2 , 3 , . . . , n
m−1
Example:
Generate 4 numbers between 0 and 1 with the following parameters: X0= 37, a = 19, c = 33 and
m = 100.
Solution:
X1 = (19*37 + 33) mod 100 = 36 r1 = 36/99 = 0.3636
X2= (19*36 + 33) mod 100 = 17 r2 = 17/99 = 0.1717
X3= (19* 17 + 33) mod 100 = 56 r3= 56/99 = 0.5656
X4= (19*56 + 33) mod 100 = 97 r4 = 97/99 = 0.9797
In the previous example, each of the parameters was given arbitrarily.
required: X0, a, c, m. However, for the algorithm to be able to achieve the
maximum lifespan N, it is necessary for those parameters to meet certain
conditions. Banks, Carson, Nelson, and Nicol suggest the following:
m=2 g
a = 1 + 4k
it must be an integer
relatively first am
it must be whole
Under these conditions, a maximum lifespan is obtained: N=m=2g
2. Multiplicative congruential algorithm
The multiplicative congruential algorithm arises from the linear congruential algorithm.
when
c = 0. Then the recursive equation is:
M =2 g
a=3+8k o a = 5 + 8k
k = 0, 1, 2, 3, ...
g−2
Under these conditions, a maximum lifespan is achieved. N=k /4=2
Example:
Generate enough numbers between 0 and 1 with the following parameters:0= 17,X
k=2y
g = 5, until finding the period or life cycle.
Solution:
a = 5 + 8 (2) = 21 and m = 32
X0= 17
r i = xi/m – 1
Example
Generate 7 pseudo-random numbers between zero and one from the following
sequence
Sean X1 = 65, X2 = 89, X3 = 98, X4 = 03, X5 = 69. To generate r1, r2, r3, r4, r5, r6 and
It is necessary to generate X^ X7, X8, X9, X10, X11, X12.
Solution:
r1 = 34/99 = 0.3434
r2=23/99 = 0.2323
r3=21/99 = 0.2121
r4 = 24/99 = 0.2424
93/99=0.9393
r6 = 27/99 = 0.2727
r7 = 50/99 = 0.5050