Question

Generate two sequences, 5000 pseudorandom numbers each, using two different PRN generators: one (Sequence A) with...

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.

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A peptide sequence was fragmented using two different methods (enzymatic and or chemical) to generate the...
A peptide sequence was fragmented using two different methods (enzymatic and or chemical) to generate the following sequences: Method 1: VMKGPPAK CDLR MNMK Method 2: KCDLR VM KGPPAKM NM a. Determind the sequence of the peptide. b. Which enzyme or chemical was used to generate the fragments in method 1? c. What type of motif or secondary structure would you expect to form in this particular peptide sequence?
python programming Question #4: # Years ago the Romans used a different system to represent numbers....
python programming Question #4: # Years ago the Romans used a different system to represent numbers. # Instead of using the digits (0, 1, 2, 3, 4, 5, 6, etc.), the Romans # formed numbers by joining combinations of the characters # (I, V, X, L, C, D, and M). # Roman Numeral characters and their integer values are: # I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, and M...
Exploring Innovation in Action Power to the People – Lifeline Energy Trevor Baylis was quite a...
Exploring Innovation in Action Power to the People – Lifeline Energy Trevor Baylis was quite a swimmer in his youth, representing Britain at the age of 15. So it wasn’t entirely surprising that he ended up working for a swimming pool firm in Surrey before setting up his own company. He continued his swimming passion – working as a part-time TV stuntman doing underwater feats – but also followed an interest in inventing things. One of the projects he began...