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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started