Question: Python Language numbers are usoful In simulations, games (e.g. dloe rolling) and cryptography. One simple way of generating a sequence of non-negative psoudo-random integers is

Python Language
numbers are usoful In simulations, games (e.g. dloe rolling) and cryptography. One simple way of generating a sequence of non-negative psoudo-random integers is to use a lnear congruential generator. It works like this. The seed, l.e. the initial number, of the sequenoe is chosen somehow. The next number to be generated is obtained by multlplying the last number generated by some integer A, then adding another integer B, and finally taking the remainder of diving by another integer C. All of A B and C are poeltive. Finding out which numbers A, B, and C produce seemingly random sequences is tricky and we leave that to mathematicians. Here we will keep things simple and use A 9,B 5, C 8. With those numbers, if the seed is 3, the next number, zero, is obtained as follows: multiply 3 and A 9 to get 27 add B-5 to get 32 divide by C 8 and take the remainder, which is0. The third number in the sequence is 5 because: multiplying 0 and 9 results in O . adding 5 results in 5 dividing by 8 and taking the remainder leads to 5 Since each number generated determines the next one, once the next number is the seed, the sequence will start repeating itself. Write a program that, given a non-negative integer seed, prints one by one a pseudo-random sequence of integers using the computation described above, and stops when the seed is printed again. The resuit for the example sequence is shown below. The answer box contains Pattern 4.5 (Sequence generation) as comments, to get you started. Write the corresponding code beneath each comment. Use variable names appropriate to the problem at hand instead of the generic names used by the pattern. Use the aet .iueut operation to get the seed number. You will have to modify slightly the pattern to obtain the expected behaviour Think which input values are admissible, i.e. won't lead to an infinite loop, and put that in your code's documentation. For example: Input Result # initialise the inputs # set value to the first value of the sequence # print value # while the termination condition is not true: # set value to the next value of the sequence # print value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
