Define a function that returns a stream of random numbers


Please answer this in Python:

There is no limit to the count of random numbers to be generated.

A common method of producing pseudo-random numbers is by means of the following recurrence relation:

R0 = seed value

Ri+1 = (a*Ri + c) % n where Ri denotes the ith pseudo-random number in the stream; a, c, and n are constant integers, and seed value is some initial value provided by the user or chosen automatically by the system.

Define a function that returns a stream of random numbers that uses this linear-congruential formula.

from operator import add, mul, mod

def make_random_stream(seed, a, c, n):

"""The infinite stream of pseudo-random numbers generated by the recurrence r[0] = SEED, r[i+1] = (r[i] * A + C) % N. Your solution must not use any lambdas or def's that we have not supplied in the skeleton.

>>> s = make_random_stream(25, 29, 5, 32)

>>> stream_to_list(s, 10) [25, 26, 23, 0, 5, 22, 3, 28, 17, 18]

>>> s = make_random_stream(17, 299317, 13, 2**20)

>>> stream_to_list(s, 10) [17, 894098, 115783, 383424, 775373, 994174, 941859, 558412, 238793, 718506]

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Define a function that returns a stream of random numbers
Reference No:- TGS02887538

Expected delivery within 24 Hours