Ask Question

A simple random generator is obtained by the formularnew = (arold+b) %mandthen settingroldtornew. Write a program that asks the user to enter an initialvalue forrold. (Such a value is often called a seed). Then print the rst 100 randomintegers generated by this formula, usinga = 32310901, b = 1729, andm = 224.

+2
Answers (1)
  1. 9 February, 10:49
    0
    The solution is written in Python

    a = 32310901 b = 1729 m = 224 rold = int (input ("Enter an initial value: ")) for i in range (100) : rnew = (a * rold + b) % m print (rnew) rold = rnew

    Explanation:

    Firstly, declare variable a, b and m and initialize them with preset value as given in the question (Line 1-3).

    Next, use input function to prompt use to input an initial value and then assigns it rold variable.

    Create a for-loop that will run for 100 iterations (Line 7). Next, apply the random generator formula to generate a random number and assign it to rnew (Line 8). Print the rnew (Line 9) and set the current rnew to overwrite the value of rold (Line 10).

    The program will generate 100 random integers.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “A simple random generator is obtained by the formularnew = (arold+b) %mandthen settingroldtornew. Write a program that asks the user to ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers