0% found this document useful (0 votes)
11 views32 pages

CH3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views32 pages

CH3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Chapter Three

Random Numbers

Derbew Felasman(Msc)
Outlines


Random Number

Types of RN

The use of random numbers

Techniques for generating random numbers

Testing Random Number

2
What is a random number?


Random numbers are numbers that are unpredictable and
have no pattern.

They are often used to represent uncertainty or chance.

Random numbers are a necessary basic ingredient in the
simulation of almost all discrete systems.

Most computer languages have a subroutine, object, or
function that will generate a random numbers.

3
Properties of RN


A sequence of random numbers, W1, W2, .. , must have two
important statistical properties
– Independence
– Uniformity

Each random number Ri, is an independent sample drawn
from a continuous uniform distribution between 0 and 1.
– F(x) = {1, 0 ≤x≤1

4
Cont..


Random number. Ri, must be independently drawn from a
uniform distribution with pdf and cdf:

PDF=Probability Distribution Function

CDF =Cumulative Probability Function

E(X)=Expected Output

5
Types of RN


True Random Numbers (TRNGs)
– TRNGs are generated by physical processes that are inherently
random
– Examples of physical processes include radioactive decay, thermal
noise, and atmospheric noise
– TRNGs are the most unpredictable type of random number, but
they are also the most difficult and expensive to generate

6
Types of RN


Pseudo-Random Number Generators (PRNGs)
– PRNGs are generated by algorithms that are designed to produce
sequences of numbers that appear to be random
– PRNGs are not truly random, but they are good enough for most
simulations and other applications that require random numbers
– PRNGs are much faster and cheaper to generate than TRNGs

7
Cont..


Pseudo means false , here it implies generating random
numbers by known method to remove the potential for true
randomness.

If the method is known then set of random numbers can be
repeated.

The main goal of random generation technique is to produce a
sequence of numbers between 0 and 1 that simulates or
imitates the ideal properties of uniform distribution and
independence.

8
Important considerations


The method should be fast, simulation process requires millions of
random numbers hence it has to be fast.

The method has to be portable to different computer

The method should have sufficiently long cycle, means there should
be long gap between the random numbers once generated getting
repeated.

The random numbers should be repeatable.

The generated random numbers should closely approximate the ideal
statistical properties of uniformity and independence
9
Errors or departures of pseudo random numbers


The generated random numbers might not be uniformly
distributed.

Generated numbers might be discrete value instead of
continuous value.

The mean of generated random numbers might be too high
or too low

The variance of generated numbers might be too high or too
low
10
Cont..


There might be dependence

Numbers successively higher or lower than adjacent
numbers

Several numbers above the mean followed by several
numbers below the mean.

11
The use of random numbers


Simulation

Sampling

Numerical analysis

Computer programming

Decision making randomness is an essential part of
optimal strategies in the theory of games

12
How are random numbers used in simulations?


Random numbers are used in simulations to introduce
uncertainty.

For example, a simulation of a queue could use random
numbers to generate the arrival times of customers.

Random numbers can also be used to generate the outcomes
of events, such as the outcome of a coin toss.

Random numbers makes simulations more realistic and
allows us to study how systems behave under different
conditions.
13
Techniques for generating random numbers


Midsquare method

Linear congruential method

Combined linear congruential generator

Random number stream

14
Midsquare Method


The Midsquare Method is a simple and straightforward
technique for generating random numbers.

First arithmetic generator: Midsquare method
– Von Neumann and Metropolis in 1940s

It involves taking an initial seed value, squaring it, and
extracting the middle digits as the next random number.

This process is repeated to generate a sequence of random
numbers.
15
Cont..


Example:
– Seed value: 1234
– Square: 1522756
– Extract middle digits: 2275
– Next random number: 2275

16
Linear Congruential Method (LCG)


Proposed by Lehmer, produces a sequences of integer numbers
X1,X2 , ...

It uses a recursive formula to produce a sequence of numbers
based on an initial seed value, a multiplier, an increment, and a
modulus.

Formula: X(n+1) = (a * X(n) + b) mod m

a is the multiplier b is the increment m is the module

Random numbers between zero and 1 can be generated by

Ri =Xi/m, i= 1,2,……
17
Cont..


Example:

X(n+1) = (23 * X(n) + 1) mod 10000

Seed value: 1234

X(1) = (23 * 1234 + 1) mod 10000 = 7299

Multiplier: 23

R(1) = 7299/10000 = 0.73

Increments: 1

X(2) = (23 * 7299 + 1) mod 10000 = 3088

Modulus: 10000

R(1) = 3088/10000 = 0.31

X(3) = (23 * 3088 + 1) mod 10000 = 4396

R(1) = 4396/10000 = 0.44
18
Example


Use the linear congruential method to generate a sequence of
random numbers and subsequent Ri values with Seed value =
27, a= 17, b = 43, and m = 100.

Here, the integer values generated will all be between zero
and 99 because of the value of the modulus. These random
integers should appear to be uniformly distributed the
integers zero to 99.

19
Cont..


The sequence of Xi and subsequent Ri values is computed as follows:

X(n+1) = (17 * X(n) + 43) mod 100

X1 = (17 * 27 + 43) mod 100 = 502 mod 100 = 2

R1=2⁄100=0. 02

X2 = (17 * 2 + 43) mod 100 = 77 mod 100 = 77

R2=77 ⁄100=0. 77

X3 = (17 * 77+ 43) mod 100 = 1352 mod 100 = 52

R3=52 ⁄100=0. 52
20
Combined Linear Congruential Generator (CLCG)


The Combined Linear Congruential Generator (CLCG)
enhances the randomness of LCGs by combining multiple
LCGs.

It takes the output of two or more LCGs and applies a bitwise
operation, such as XOR or addition, to generate the final
random number.

Formula: X(n) = (X1(n) XOR X2(n))

21
Cont..


Example:

LCG1: Seed value: 1234, Multiplier: 23, Increment: 1, Modulus:
10000

LCG2: Seed value: 5678, Multiplier: 17, Increment: 3, Modulus:
10000

X(n) = (LCG1 XOR LCG2)

22
Random Number Stream


A random number stream is a sequence of random numbers
generated by a specific algorithm.

Each stream has unique properties and characteristics,
making them suitable for different applications.

Common random number streams include:
– Mersenne Twister
– Xorshift
– RC4
23
Cont..


Mersenne Twister is a widely used random number stream known for its
high-quality random numbers. It has a long period and produces
sequences that pass sentient statistical tests.

The Xorshift is a relatively new random number stream known for its
speed and efficiency. It produces high-quality random numbers using
bitwise operations, making it suitable for real-time applications.

The RC4 is an older but still widely used random number stream. It was
once considered a secure stream but has since been found to have
vulnerabilities. However, it remains efficient and is still used in some
applications.
24
Testing Random Number


Testing RNGs is essential to ensure they produce high-quality,
unpredictable sequences of numbers.

By employing various statistical tests, we can evaluate the
quality of RNGs and identify any biases or non-randomness in
the generated sequences.

This process helps us maintain the integrity of various
applications that rely on random numbers, from cryptography
to simulations to gaming.
25
Why Test Random Number Generators?


Reliability: Ensuring that RNGs produce consistent and
reliable random numbers

Unpredictability: Verifying that RNGs are not susceptible to
patterns or predictable sequences

Quality: Assessing the overall randomness and statistical
properties of the generated numbers

26
Common Testing Techniques


Frequency Tests: Checking that the frequency of each possible
value is close to the expected frequency

Correlation Tests: Checking that there is no correlation
between successive random numbers

Pattern Tests: Checking that there are no patterns in the
sequence of random numbers

27
Frequency Tests


Chi-Square Test: Measures the deviation between the
observed and expected frequencies of each value.

Kolmogorov-Smirnov Test: Compares the cumulative
distribution function (CDF) of the generated numbers to the
expected CDF.

28
Correlation Tests


Serial Correlation Test: Checks for correlation between
adjacent random numbers

Lag Correlation Test: Checks for correlation between random
numbers separated by a specific lag

29
Pattern Tests


Monobit Test: Checks the proportion of ones and zeros in the
binary representation of the generated numbers

Runs Test: Checks the number of runs of consecutive ones or
zeros in the binary representation of the generated numbers

30
Testing Frameworks


NIST Statistical Test Suite (STS): A comprehensive suite of tests
developed by the National Institute of Standards and
Technology (NIST) for evaluating the randomness of
cryptographic RNGs

Dieharder Test Suite: A widely used suite of tests for assessing
the statistical properties of RNGs

31
END!

32

You might also like