Develop a data type for generating pseudo-random numbers. That is, convert StdRandom to a data type. Instead

Question:

Develop a data type for generating pseudo-random numbers. That is, convert StdRandom to a data type. Instead of using Math . random (), base your data type on a linear congruential generator. This method traces to the earliest days of computing and is also a quintessential example of the value of maintaining state in a computation (implementing a data type). To generate pseudo-random int values, maintain an int value \(x\) (the value of the last "random" number returned). Each time the client asks for a new value, return \(a * x+b\) for suitably chosen values of \(a\) and \(b\) (ignoring overflow). Use arithmetic to convert these values to "random" values of other types of data. As suggested by D. E. Knuth, use the values 3141592621 for a and 2718281829 for b. Provide a constructor allowing the client to start with an int value known as a seed (the initial value of \(\mathrm{x}\) ). This ability makes it clear that the numbers are not at all random (even though they may have many of the properties of random numbers) but that fact can be used to aid in debugging, since clients can arrange to see the same numbers each time.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: