UCB CS61A 题

avatar 265351
DavisXie
3512
3
请求高手帮帮忙, 把这题给刷了。 来在 UC B HW08 的 题目

Question 7: Linear Congruential GeneratorA common method of producing pseudo-random numbers is by means of thefollowing 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 usesthis linear-congruential formula.
from operator import add, mul, moddef 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
3条回复