Emon 1
Emon 1
S i m u l a t i o n a n d M o d e l i n g – S TA 4 0 1
Submitted To Submitted By
Dr. Md. Murad Hossain Ashraful Islam Emon
Assistant Professor Student ID: 19STA014
Dept. of Statistics, Date of submission
BSMRSTU 08- 09-2024
Generation of Random Numbers
A random number is a value that is generated unpredictably, ensuring that every potential
outcome has an equal opportunity for selection, resulting in a sequence that appears both uniform
and independent.
Random number generation is a core of simulation and is a very broad topic that embraces such
areas as cryptography, statistical sampling, computer simulations, and many others. Probability
analysis is implemented in random numbers in the model and analyses the systems that are totally
stochastic or contain stochastic components. Numerically generated random numbers aim to create
such sequences whose progression or lack of it cannot be predicted, more importantly in the
encryption of information, in statistics sampling, in computer simulations, in fair chance or
probability in stochastic games, and in random experiments. This blind guarantees a standard
degree of randomness making it important for applications, which entail securitization, fairness,
and accurate chance mechanisms in areas such as cryptography, simulation, and research.
2. Independence: The selection of each random number does not influence the preceding
numbers.
3. Reproducibility: Knowing the initial value (seed) for generating pseudorandom numbers
allows you to recreate the exact series.
• Monte Carlo simulations are often used to model complicated systems, for example, to
approximate π.
• Cryptography depends on them to create un-hackable keys.
• Statistical sampling ensures that the selection of participants in surveys is unbiased.
• Gaming uses them to introduce randomness, for example, shuffling cards.
• It is used in training models in machine learning and to give initial weights.
• Randomized algorithms speed up problem solving.
• Computer graphics can achieve photorealism by generating the textures randomly.
• Quality Control uses random sampling to ensure a consistent product.
These are derived from fundamentally unpredictable physical phenomena. Since they originate
from natural phenomena, they can never be reproduced or predicted. True random numbers are the
only ones acceptable in applications requiring high security and real unpredictability.
Example: One might use a hardware random number generator based on environmental noise,
such as the random electrical noise in a resistor or the intervals between events of radioactive
decay. For instance, a piece of hardware might count the time between radioactive particle
emissions and use that count to produce the bits of encryption keys, making them extremely
unpredictable.
2. Pseudorandom Numbers:
These are generated using computational algorithms to simulate randomness. They are not random
in the true sense but are so for most purposes, especially where reproducibility is handy.
Pseudorandom number generators, starting with an initial value called a seed, use it in producing
a sequence of numbers that appears random. If the same seed is used, the same sequence will be
generated. This comes in handy in cases where debugging and testing are related.
Example: The Mersenne Twister algorithm, a very famous PRNG, is in use for generating random
numbers used in simulations of scientific research. In the Monte Carlo method for estimating π,
for example, millions of random points are generated within a square, and then the ratio of those
that fall inside a quarter circle is counted. If the seed is the same, researchers in their own right get
the results exactly, therefore showing consistency and reliability in studies.
Random number generation
Random number generation is the technique of creating a sequence of numbers or symbols that
cannot be predicted more accurately than by chance. Physical mechanisms (such as rolling a die)
and computational algorithms can both generate random numbers.
TRNGs use physical processes to produce random numbers. These processes include electrical
noise, radioactive decay, and several natural events. TRNGs are regarded truly random because
they are based on naturally unexpected physical processes.
Physical Processes:
• Radioactive Decay:
Measures the time between particle emissions from a radioactive source. Since radioactive
decay is fundamentally random, it provides a highly unpredictable source of randomness.
Example: A Geiger counter attached to a computer system that records the time between
radioactive decay events and translates them to random numbers.
• Thermal noise :
The thermal noise works by using the random electrical noise created by resistors or any other
electronic component in the thermal agitations of electrons. It amplifies this noise, digitizing
it to then output random numbers.
Example: A circuit that catches the small variations of voltage over a resistor, due to thermal
noise, and translates the variations into random numbers.
• Photon Detection:
The third approach relies on the detection of individual photons and the arrival times of each.
Quantum processes are, by definition, random—for example, photon emission and detection.
Example: Quantum random number generator, a beam splitter sends photons to two detectors,
and the random detection events will be used in generating truly random numbers.
PRNGs are algorithms that, by being deterministic, produce a sequence of numbers that appear to
be random. Starting with a seed value, they use a series of mathematical operations to generate
their sequence of numbers. Not truly random, PRNGs are nonetheless good enough in most
practical cases, as they can produce very long sequences of statistically random numbers.
The LCG is one of the most basic and well-known forms of PRNGs, generating a series of
pseudorandom numbers by a linear recurrence relation. LCGs are simple to create and compute,
but they have substantial disadvantages, such as shorter lifetimes and correlations between
subsequent readings.
• Mersenne Twister
Mersenne Twister is one of the most well-known PRNGs for its long period and high randomness.
It strikes a great balance between speed and quality, which is best suited for many applications,
including simulations, games, and statistical sampling. The approach employs a matrix linear
recurrence over a finite binary field to obtain its long period and distribution characteristics.
XOR Shift generators are a type of algorithm for generating pseudorandom numbers, building on
the XOR and bit shift operations. These operations are very fast to execute and can produce high-
quality random sequences. XOR Shift generators are very simple and fast; thus, they are
widespread in applications where computational efficiency is a factor. The quality of randomness
may vary, and some implementations have periods shorter than more complicated PRNGs, such
as the Mersenne Twister.
• Cryptographically Secure Pseudorandom Number Generators (CSPRNGs)
CSPRNGs are designed to produce high-quality randomness for cryptographic purposes , not just
a reliable source but a secure one. They generate sequences such that it becomes very difficult to
predict the next number even if parts of the sequence or the seed have been given CSPRNGs use
quite intricate algorithms with cryptographic methods to ensure the randomness and security of
the generated numbers.
Sobol Sequences: Often used for high-dimensional numerical methods, especially Monte Carlo
simulations, to uniformly sample.
Example: Pricing financial derivatives using Monte Carlo simulations.
Halton Sequences: Is used in multidimensional numerical integration to distribute the points
uniformly.
Example: Integrating functions over multi-dimensional spaces.
Faure Sequences: Give low-discrepancy points for quasi-Monte Carlo methods.
Example: Solution of numerical problems in uniform sampling.
Procedure of the Multiplicative Congruential Pseudorandom
Number Generation Technique
The MCM is a form of PRNG which produces a sequence of numbers by a mathematical formula.
It involves defining an initial value, then applying on it a multiplicative constant and each time
resulting value is used to comprise the next one in the sequence.
Initialization:
Formula:
The general formula for the next number in the sequence is:
Steps:
3. Repeat:
o Use Xn for the next Xn-1 and repeat the computation to generate further numbers
in the sequence.
If, X0=16, and Xn= (9Xn-1+4) mod 100, then find the first 10 random
number X1,X2,….X10 and Pseudorandom Number.
Solution:
Here, an initial seed value X0= 16
0 X0=16 0.16
1 X1=(9*16+4) mod 300=48 0.48
2 X2=(9*48+4) mod 300=36 0.36
3 X3=(9*36+4) mod 300=28 0.28
4 X4=(9*28+4) mod 300=56 0.56
5 X5=(9*56+4) mod 300=8 0.08
6 X6=(9*8+4) mod 300=76 0.76
7 X7=(9*76+4) mod 300=88 0.88
8 X8=(9*88+4) mod 300=96 0.96
9 X9=(9*96+4) mod 300=68 0.68
10 X10=(9*68+4) mod 300=16 0.16
x=16
y=c(x)
for(i in 2:11){
y[i]=(y[i-1]*9+4) %% 100
}
value=y/100
my_data <- data.frame(y,value)
The procedure of using Random Numbers to compute integral
We want to compute the area of a curve g(x) between x=0 and x=1
1
Ѳ=∫0 𝑔(𝑥 )𝑑𝑥
Step1: Generate random numbers U1,U2,…,Uk that are uniformly distributed between 0 and 1
Step 2: Count the number of points that fall inside the circle.
Step 3: Estimate π using the ratio of points inside the circle to the total number of points.
Purpose: See if number of zeros and number of ones are almost the same in a given binary
sequence.
Application: It is applied to maintain range of a sequence not significantly different from 0 and 1
which is obligatory for creation of fair cryptographic keys or random samples.
Runs Test
Purpose: looks at the frequency and size of a run – this is a series of one kind of bit in succession.
Application: Prevents the sequence from passing more runs than necessary, thus increasing and
providing randomness into the sequence.
Chi-Square Test
Purpose: Analyzes the differences in ratio of outcome’s occurrence compared to the expected
frequency ratio in order to determine uniformity.
Application: Subscribed as a measure in establishing the validity of a given data set to a given
distribution is very important for simulations and modeling.
Autocorrelation Test
Purpose: Quantifies coverability of two numbers in a sequence at a particular lag or difference also
called time shift of the data stream.
Application: Makes it possible to keep separate various factors in a sequence which is suitable for
such application as simulation and cryptography to eliminate predictability, if desired.
Poker Test
Purpose: Examines the sequence by pairing numbers and counting how often different values occur
in the same grouping as those in poker.
Application: Identifies regularities and outliers in the distribution of sequences which finds
application in randomness tests used in games and encryption.
Kolmogorov-Smirnov Test
Purpose: Therefore, used the Chi Square Test to compares the sample distribution with the
expected uniform distribution.
Application: In hypothesis testing and other statistical analysis to check the randomness of data is
very useful especially when testing random number generators.
Spectral Test
Purpose: The goal here is to examine the Fourier transform of the sequence for periodicity.
Application: Periodogram analysis is applied to signal processing and randomness testing, mainly
to remove periodicities that might indicate a series is not random.
Entropy Test
Purpose: The purpose of this test is to establish randomness within a sequence it calculates its
entropy.
Application: Used in assessing the randomness and information content of the sequence. This is
important, for example, for cryptographic uses that need it for proper generation of secret keys and
nonpredictable data encryption.