Starting from:

$35

Python’s Random Number Generator and Bernoulli Trials

Python’s Random Number Generator and Bernoulli Trials
Location of Particle Determined by Bernoulli Random Variables
(Simple Markov Chain)
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].
Bernoulli R.V.
A program in Python that simulates a Bernoulli RV is provided with this outline. The program prompts the user
to input the probability of success and the number of trials (experiments) to be performed. The program outputs
a 1 for success or a 0 for failure depending on the outcome of the RV.
Part 2, Discrete Markov Chain
There are two points labeled 0 and 1 on a plane that will be referred to as states. Further there exists a particle.
This particle can be located either at state 0 or state 1. When the particle is located at state 0 its future behavior
is governed by random variable (RV) A. The RV 𝐴 is a Bernoulli RV. The particle can stay at state 0 with
probability 1 – 𝑝 and it can go to state 1 with probability 𝑝. When the particle is located at state 1 its future
behavior is governed by the Bernoulli RV 𝐵. The particle will stay at state 1 with probability 1 – 𝑞 and will go
to state 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
Present Next Step
0 0
1
1
1 − 𝑝
1 − 𝑞
0 1
𝑝
𝑞
1 − 𝑝 1 − 𝑞
coins 𝐴 and 𝐵. When you are at state 0 you flip coin 𝐴 and when you are at 1 you flip coin 𝐵. When at a state
the Bernoulli RV will dictate how you proceed. Whether moving from state 0 to state 1 or vice versa we’ll refer
to this as a step. Likewise, if you remain at a state, because of the outcome of the Bernoulli RV, this will be
referred to as a step.
A program in Python that simulates the behavior of the particle discussed above is provided with this outline.
The values of the parameters 𝑝 and 𝑞 are inputted by the user. The output shows the states 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

More products