$29.99
Python’s Random Number Generator and Bernoulli Trials
Location of Particle Determined by Bernoulli Random Variables
(Simple Markov Chain)
EE 381 – Project 3, 5 Points
Date Due: 3-1-2021
Introduction: A Bernoulli random variable (RV) is one of the basic RV a person studying probability should be
familiar with. A direct application of the random number generator available in Python allows for the
simulation of Bernoulli random variables. Further, Bernoulli RV can be used to model a real world
probabilistic entity such as flipping a coin.
Suppose that a trial, or an experiment, whose outcome can be classified as either a “success” or as a “failure” is
performed. If we let 𝑋 equal 1 if the outcome is a success and 0 if it is a failure, then the probability mass
function of 𝑋 is given by
𝑝(0) = 𝑃[𝑋 = 0] = 1 − 𝑝
𝑝(1) = 𝑃[𝑋 = 1] = 𝑝
where 𝑝, 0 ≤ 𝑝 ≤ 1, is the probability that the trial is a “success”.
A random variable 𝑋 is said to be a Bernoulli random variable if its probability mass function is given by the
above for some 𝑝 ∈ [0,1].
Part 1, Bernoulli R.V.
Write a program in Python that simulates a Bernoulli RV. The program should prompt the user to input the
probability of success and the number of trials (experiments) to be performed. The program should output a 1
for success or a 0 for failure depending on the outcome of the RV. Use Pythons random number generator.
Possible code would be: r = random.uniform(0,1).
Part 2, Discrete Markov Chain
There are two points labeled 0 and 1 on a plane that will be referred to as nodes. Further there exists a particle.
This particle can be located either at node 0 or node 1. When the particle is located at node 0 its future behavior
is governed by random variable (RV) A. The RV 𝐴 is a Bernoulli RV. The particle can stay at node 0 with
probability 1 – 𝑝 and it can go to node 1 with probability 𝑝. When the particle is located at node 1 its future
behavior is governed by the Bernoulli RV 𝐵. The particle will stay at node 1 with probability 1 – 𝑞 and will go
to node 0 with probability 𝑞. This behavior can be presented diagrammatically.
Without delving too deeply into the theory of the behavior of such a system is it possible to write a computer
program that effectively simulates the behavior of the system? Consider yourself to be the particle with two
coins 𝐴 and 𝐵. When you are at node 0 you flip coin 𝐴 and when you are at 1 you flip coin 𝐵. You’ll need a
random number generator over [0, 1). When at a node the Bernoulli RV will dictate how you proceed.
Whether moving from node 0 to node 1 or vice versa we’ll refer to this as a step. Likewise, if you remain at a
node, because of the outcome of the Bernoulli RV, this will be referred to as a step.
Instructions:
1.) Write a program in Python that simulates the behavior of the particle discussed above. The values of the
parameters 𝑝 and 𝑞 will be inputted by the user. The particle can start at a random location or the user
can input the starting position. Have it go through 25 steps (this includes the first step). The output
should show the steps on the nodes the particle goes through. Try the following inputs and note the
results.
a.) 𝑝 = 𝑞 = 0
b.) 𝑝 = 1 − 𝑞
c.) 𝑝 = 𝑞 = 1
d.) 0 < 𝑝 < 1 and 𝑞 = 1
e.) 0 < 𝑝 < 1 and 0 < 𝑞 < 1
During the laboratory meetings of 2/17, 2/22, and 2/24 a program in Python that meets the above requirements
will be written.
Deliverables: The students will make a PDF version of the two programs and submit both their Python file and
the PDF with name and ID # to dropbox.
Present Next Step
0 0
1
1
1 − 𝑝
1 − 𝑞
0 1
𝑝
𝑞
1 − 𝑝 1 − 𝑞