Post on 15-Apr-2017
©TechKnowXpress
PSEUDO RANDOM NUMBER GENERATION
-DARSHINI PARIKH
(TechKnowXpress)
©TechKnowXpress
WHAT ARE PSEUDO RANDOM NUMBERS(PRNs)?
• Deterministic Algorithms used to generate a sequence of numbers that are not statistically random.
• Good algorithms pass a number of tests of randomness.
©TechKnowXpress
RANDOMNESS
• Uniform Distribution – frequency of occurrence of numbers
• Independence – inference of a subsequence should not be possible
©TechKnowXpress
CONGRUENTIAL GENERATOR
FOUR TYPES LINEAR CONGRUENTIAL GENERATOR(LCG)
MULTIPLICATIVE CONGRUENTIAL GENERATOR(MCG)
QUADRATIC CONGRUENTIAL GENERATOR(QCG)
INVERSIVE CONGRUENTIAL GENERATOR(ICG)
©TechKnowXpress
MCG
• Recurrence Relation:
Xn+1 = (a* Xn +c) mod m
a=Multiplier
c= Increment = 0 (ZERO)m=modulus
• Xn+1 = (a* Xn ) mod m
©TechKnowXpress
MCG EXAMPLE
Eg: X0 = a = c = 7m = 10
PRNs generated:
7, 6, 9, 0, 7, 6, 9, 0, ...
Eg: m=231
Range of PRNs – {0 - 231}
©TechKnowXpress
MCG Example (conti…)
a = 13
c = 0
m = 64
©TechKnowXpress
LCG
Recurrence Relation:
Xn+1 = (a* Xn +c) mod m
a=Multiplierc= Incrementm=modulus
©TechKnowXpress
SELECTING ‘a’ IN LCG
FOR GENERATING ANY LCG
a belongs to: {0 – m}
FOR GENERATING FULL PERIOD LCG
(i) (a-1) should be divisible by all prime numbers of m.
(ii) (a-1) should be divisible by 4 if m is divisible by 4
©TechKnowXpress
SELECTING ‘m’ & ‘c’ IN LCG
SELECTING M
(i) M should be large(ii) For efficient
computation; m should be a power of 2.
SELECTING C
C belongs to {0 to m}
©TechKnowXpress
LCG Example
Xn+1 =65539Xn mod 231
This PRNG generates a full period sequence
©TechKnowXpress
QCG
RECURRENCE RELATION:
Xn+1 = (a* X2n + b*Xn + c) mod m
a, b – multipliers
c - increment
m - modulus
©TechKnowXpress
CRITERIA FOR FULL PERIOD SEQUENCE
gcd(m,c) = 1; m and c are relatively prime
a,b =0 (mod p);p = odd prime divisor of m
a=0 (mod 2) and b=(a+1) (mod 4) if 4|m or b=(a+1) (mod 2) if 2|m
if 9|m then either a=0 (mod 9) or b=1 (mod 9) and ac=6 (mod 9).
m=2p
c = 1 (mod 2) => c is odd a = 0 (mod 2) => a is even b= (a+1) (mod 4)
©TechKnowXpress
QCG Example
Xn+1 = (12*Xn2 + 25* Xn + 11) % 36
X0 = 13
Corresponding equation:
Now , 36 – (22 * 32)
Criteria satisfied:
gcd (c,m) = 1 (gcd(11,36) = 1)
a % 2 = a % 3 =0 (a=12)
b % 2 = b % 3 = 1 (b=25)
b = a+1 (mod 4) (25=13 (mod 4))
a*c = 6 (mod 9) (12*11 = 6 (mod 9))
This PRNG will generate a full period sequence
©TechKnowXpress
ICG
RECURRENCE RELATION:
X(n+1) = a*X-1n + c (mod m)
a – multiplier
c – increment
m - modulus
©TechKnowXpress
CRITERIA FOR FULL PERIOD SEQUENCE
POLYNOMIAL:
X2 - c*X – a
should be a primitive polynomial over Fm.
(Inversive Maximum Polynomial (IMP).)
©TechKnowXpress
ICG Example
Eg: X(n+1) = 2*X-1n + 3 (mod m)
Corresponding Equation: X(n+1) = a*X-1n + c (mod m)
IMP : Xn2 -3 * Xn -2= Xn
2 + 4* Xn + 5 (mod 7) is a primitive polynomial over F7.
This PRNG will generate a full period sequence
Sequence generated: 1,5,2,4,0,3,6,1…
©TechKnowXpress
Lagged Fibonacci Generator (LFG)
RECURRENCE RELATION:
Xn = (X(n-L) * X(n-k)) mod m
Given – L bits of the sequence
k, L – lags
m = 2M
Period of the Generator = (2L-1)*(2M-1)
LFG Notation: LFG(L, k, M)
©TechKnowXpress
LFG Example
Eg: LFG (17,5,31)
So the period of this sequence will be approx. 247
247 = (217) * (2(31-1))
©TechKnowXpress
LFSR
©TechKnowXpress
LFSR Example
Suppose m – 24 -1
Initial value: 1000
Sequence: 1000, 1001, 1010, 1111,…
©TechKnowXpress
Mersenne Twister
RECURRENCE RELATION
X(k+n) = X(k+m) ⊕ (Xuk | XL
(k+1)) • A
A – w x w matrix
r - 0< r <w-1
m – 1< m <n
k – {0,1,….}
u – higher order bits = w-r bits
L – lower order r bits
| - Concatenation Operation
©TechKnowXpress
BLUM BLUM SHUB GENERATOR
RECURRENCE RELATION:
Xn+1 = X2n % m
X0 = S2 % m
Bn+1 = Xn+1 % 2
S – Seed value
m – modulus – p*q (p & q are large primes such that p=q=3 (mod 4))
B – BBS bit
©TechKnowXpress
BBSG Example
Eg: p- 383, q – 503, S = 101355
m =192649 = 383 * 503
The sequence generated is:
©TechKnowXpress
ANSI X9.17
©TechKnowXpress
ANSI X9.17 (conti…)
RECURRENCE RELATION:
Ri = EDE([K1,K2], [Vi ⊕ EDE([K1,K2],DTi)])
Vi+1 = EDE([K1,K2], [Ri⊕ EDE([K1,K2],DTi)])
©TechKnowXpress
APPLICATIONS OF RANDOM NUMBERS
CRYPTOGRAPHY
STATISTICAL SAMPLING
GENERATION OF
INITIALIZATION VECTORS
SIMULATIONS
GAMBLING&
LUCKY DRAWS
©TechKnowXpress
APPLICATIONS OF PRNGSs
GENERATION OF SESSION
KEYS
GENERATION OF PUBLIC
KEYS
GENERATION OF NONCE TO AVOID REPLAY ATTACKS
©TechKnowXpress