74.4k views
4 votes
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.

User Hugohabel
by
3.5k points

1 Answer

7 votes

Answer:

The solution is written in Python

  1. a= 32310901
  2. b= 1729
  3. m= 224
  4. rold = int(input("Enter an initial value: "))
  5. for i in range(100):
  6. rnew = (a * rold + b) % m
  7. print(rnew)
  8. rold = rnew

Step-by-step 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.

User IgorOK
by
3.7k points