Question: Please write in java i. Question 2 [35 PTS]: We have already practiced random numbers. There are several ways to get a pseudo-random number. You

Please write in java

 Please write in java i. Question 2 [35 PTS]: We have

i. Question 2 [35 PTS]: We have already practiced random numbers. There are several ways to get a pseudo-random number. You are about to create your own way of pseudo-random number generation. We are about to use the following algorithm: The Lehmer random number generator (named after D. H. Lehmer), is a type of linear congruential generator (LCG) that operates in multiplicative group of integers modulo n. The general formula is: Xx+1 = 2 Xx mod m Xo is seed (initial value to start the sequence). If user does not want to specify it, by default, take 42. a is multiplier. mis modulus. There are of course constraints to choose Xo, a and m. For practical purposes we will use our own. Main points: 1. Define a class Random Generator which will enable user to perform the following operations: a. Instantiate using a seed OR without a seed (in this case, default value of seed is 42) b. int nextInt(); return the next element of the abovementioned sequence (pseudo-random number) c. int nextInt(int bound); returns an integer in the range [O-bound) note: the elements of the sequence might be negative as well. d. double nextUniform(); returns an integer in the range (0-1) Explanation (for practical purposes): Assume that we have seed = 1, modulus = 13, multiplier = 3. Normally the sequence looks 39139 139 13...... If with the same setup, we change the seed to 2, then sequence becomes 65 265 265 26. Test your code with modulus =2_147_483_647 and multiplier = 243. In the main() method of Question2 class create RandomGenerator instance and test its methods by printing: 10 random numbers 10 random numbers in range (0-9) 10 random uniform numbers (with 2 digits after decimal) Example Input: Example output RandomGenerator rand = new Random Generator(42); for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!