Generate two sequences, 5000 pseudorandom numbers each, using two different PRN generators: one (Sequence A) with MCG, and another (Sequence B) – by using the PRN function built in the programming language you use (e.g. RND( ), RAND[ ], etc.). (Use python)
Then, plot two the sequences into two separated graphs.
Here is the code:
import random
import itertools
sequence_b = list()
sequence_b.extend([random.randrange(100) for item in range(100)]) #PNR
x_axis = list()
x_axis.extend([item for item in range(100)])
# Multiplicative Congruence method for generating Pseudo Random Numbers
def multiplicativeCongruentialMethod(Xo, m, a, randomNums, nums): # MCG
sequence_a[0] = Xo # Initialize the seed state
for i in range(1, nums): # Traverse to generate required numbers of random numbers
sequence_a[i] = (randomNums[i - 1] * a) % m # Follow the linear congruential method
# initializing the parameters
Xo = 7 # Seed value
m = 15 # Modulus parameter
a = 7 # Multiplier term
nums = 100 # Number of Random numbers to be generated
sequence_a = [0] * (nums) # To store random numbers
# Function Call
multiplicativeCongruentialMethod(Xo, m, a, sequence_a, nums)
sequence_a[:5]
pair_sequence_a = list()
pair_sequence_b = list()
pair_sequence_a = [(i, j) for i, j in zip(x_axis, sequence_a)]
pair_sequence_b = [(i, j) for i, j in zip(x_axis, sequence_b)]
import matplotlib.pyplot as plt
plt.scatter(*zip(*pair_sequence_a))
plt.scatter(*zip(*pair_sequence_b))
Here is the output:
It is a scatter plot for random number with sequence number because we need both x axis and y axis to plot.
For any doubts, please comment below.
Get Answers For Free
Most questions answered within 1 hours.