Starting from:

$29.99

Random Number Generator (RNG)

Random Number Generator (RNG)
Solution to Probability Problem through Simulation
EE 381 – Project 1, 5 Points

Introduction
Random Number Generator
In this project we will explore what is sometimes referred to as a random number generator. The linear congruential
generator is a pseudorandom number generator that the reader may already be familiar with. This is the type of
pseudorandom number generator that will have a definite pattern yet will appear to have no discernible pattern detectible
without knowing the exact formula used. Random means no pattern while pseudorandom means no apparent pattern. The
formula can be expressed as
𝑆𝑖+1 = (𝑀 ∗ 𝑆𝑖 + 𝐴)𝑚𝑜𝑑 𝑁
where 𝑀 is the multiplier, 𝐴 is the adder, 𝑁 is the norm. The first seed is 𝑆0 and each subsequent seed is determined from
each iteration of the formula.
Do the following exercises below on paper by hand.
Exercise 1
Given the values below determine the pseudorandom number sequences for seed values of 0 and 4. Calculate a list of
sixteen values.
𝑀 = 6, 𝐴 = 5, and 𝑁 = 11.
Exercise 2
For the generator 𝑆𝑖+1 = (6 ∗ 𝑆𝑖 + 3)𝑚𝑜𝑑 7 determine the pseudorandom number sequences for the following initial seed
values, 0, 1, 4, and 5. Calculate a list of ten values.
There is a theorem that gives the requirements for the optimal values to be used in the generator.
Theorem (Statement without proof.)
The pseudorandom number generator will produce the maximum cycle length 𝑁 of pseudorandom numbers with any
initial value of 𝑆 under either of these conditions:
For base ten (decimal numbers)
𝑁 is a power of 10, 𝐴 ends in (unit digit) 1, 3, 7, or 9, and 𝑀 − 1 is a multiple of 20.
For base two (binary numbers)
𝑁 is a power of 2, 𝐴 is odd, and 𝑀 − 1 is a multiple of 4.
The interested reader can use the values below and a seed of 0 to observe that the generator has a length of 16.
𝑁 = 16, 𝐴 = 7, 𝑀 = 21
Pseudorandom number generator for use in this project
Write a program in Python that generates 100 pseudorandom numbers in [0, 1). Format it to four decimal positions.
Use 𝑁 = 10000, 𝐴 = 4857, 𝑀 = 8601.
-------------------------------------------------------------------------------------------------------------------------------------------
Simulations using our pseudorandom number generator
Example 1: Flipping a Coin
Use the pseudorandom number generator to simulate a coin being flipped twenty five times.
Example 2: Rolling a Die
Use the pseudorandom number generator to simulate a die being rolled twenty five times.
------------------------------------------------------------------------------------------------------------------------------------------
To the student: A significant portion of the preceding is from F. Solomon’s “Stochastic Processes”
Instructions: During the laboratory meetings of 1/25 and 1/27 our pseudorandom number generator program will be
written in Python and it will be used to do the simulations above.
Deliverables: A copy (picture) of the work done by hand, a PDF version of the programs with the output, and the Python
file all with name and ID # to dropbox.

More products