You can find the solution with Objective:
1.Write a program to implement Linear Congruential Generators in python.
2.Write a program to implement Bernouli distribution in python.
3. Write a program to implement Binomal distribution in python.
4. Write a program to implement geometry distribution in python.
5. Write a program to find GCD in python.
6. Write a program to find LCM in python.
A lab report on modeling and simulation with python code
1. Experiment Name: Write a program to implement Linear Congruential Generators in
python.
Objective: A linear congruential generator (LCG) is an algorithm that yields a sequence of
pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. This
program is to implement LCG.
Source Code:
m=16;
a=5.0;
c=3.0;
z=7.0;
for num in range (1,21):
r=(a*z+c)%m;
z=r;
#print z/m;
print r ;
Reference: https://en.wikipedia.org/wiki/Linear_congruential_generator
2. Experiment Name: Write a program to implement Bernouli distribution in python.
Objective: The Bernoulli distribution essentially models a single trial of flipping a weighted
coin. It is the probability distribution of a random variable taking on only two values,
1 ("success") and 0 ("failure") with complementary probabilities p and 1-p respectively. This
program is to implement Bernouli distribution in python.
Source Code:
u = []
def test(p):
printf()
if u[0]<=p:
return 1
else:
return 0
def printf():
m=16;
a=5.0;
c=3.0;
z=7.0;
for num in range (1,21):
r=(a*z+c)%m;
#print r;
z=r;
u.append(z/m)
3. #print z/m;
#print r,z/m ;
p = input("")
a = test(p)
print u
print a
Reference: https://brilliant.org/wiki/bernoulli-distribution/
4. Experiment Name: Write a program to implement Binomal distribution in python.
Objective: A binomial distribution is the sum of independent and identically distributed
Bernoulli random variables. This program is to implement Binomal in python.
Source Code:
u = []
count = []
m = 16
a = 5
c = 3
z = 7
for num in range (m):
r = (a*z+c)%m
z = r
u.append(float(z)/m)
print u
def test(w):
count = 0
for i in w:
print u[0] ," ",i
if u[0]<=i:
count+=1;
return count
p = []
5. f = input("")
fori in range(f):
j = input("")
p.append( float(j))
l = len(p)
c = test(p)
print c," ",l
print float(c)/float(l)
Reference: http://onlinestatbook.com/2/probability/binomial.html
6. Experiment Name: Write a program to implement geometry distribution in python.
Objective: The geometric distribution is a special case of the negative binomial distribution. It
deals with the number of trials required for a single success. Thus, the geometric distribution is a
negative binomial distribution where the number of successes (r) is equal to 1. This program is to
implement geometry algorithm in python.
Source Code:
u = []
count = []
m = 16
a = 5
c = 3
z = 7
for num in range (m):
r = (a*z+c)%m
z = r
u.append(float(z)/m)
print u
def test(w):
count = 0
for i in w:
print u[0] ," ",i
if u[0]<=i:
count+=1
7. else:
break
return count
p = []
f = input("")
fori in range(f):
j = input("")
p.append( float(j))
l = len(p)
c = test(p)
print c," ",l
print float(c)/float(l)
Reference: stattrek.com/statistics/dictionary.aspx?definition=geometric_distribution
8. Experiment Name: Write a program to find GCD in python.
Objective: The greatest common divisor (G.C.D) of two numbers is the largest positive integer
that perfectly divides the two given numbers. This program is implementing to find GCD
number.
Source Code:
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
a = input("Enter first number: ")
b = input("Enter second number: ")
result = gcd(a,b)
print result
Reference: https://www.programiz.com/python-programming/examples/hcf
9. Experiment name: Write a program to find LCM in python.
Objective: The least common multiple (L.C.M.) of two numbers is the smallest positive
integer that is perfectly divisible by the two given numbers. This program is to implement LCM
in python.
Source Code:
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
a = input("Enter first number: ")
b = input("Enter second number: ")
result = gcd(a,b)
print a*b/result
Reference: https://www.programiz.com/python-programming/examples/lcm