Question: From Introduction to Computing Using Python: An Application Development Focus 8.36 Implement class Pseudorandom that is used to generate a sequence of pseudorandom integers using

From Introduction to Computing Using Python: An Application Development Focus

8.36 Implement class Pseudorandom that is used to generate a sequence of pseudorandom integers using a linear congruential generator. The linear congruential method generates a sequence of numbers starting from a given seed number x. Each number in the sequence will be obtained by applying a (math) function f (x) on the previous number x in the se- quence. The precise function f (x) is defined by three numbers: a (the multiplier), c (the increment), and m (the modulus):

f(x) = (ax+c) mod m

For example, if m = 31, a = 17, and c = 7, the linear congruential method would generate the next sequence of numbers starting from seed x = 12: 12,25,29,4,13,11,8,19,20, . . .because f (12) = 25, f (25) = 29, f (29) = 4, and so on. The class Pseudorandom should support methods:

__init__(): Constructor that takes as input the values a, x, c, and m and initializes the Pseudorandom object next(): Generates and returns the next number in the pseudorandom sequence

>> x = pseudorandom(17, 12, 7, 31)

>>> x.next()

25

>>> x.next() 29

>>> x.next()

4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!