Random number generator Write your own integer random number generator as a class that uses a formula to obtain the next pseudo-random number from the previous one. A random number program works by starting with some ‘seed’ value. Thereafter the current random number is used as a basis for the next by performing some calculation on it which makes it into some other (apparently random) number. A good formula to use for integers is:
nextR = ((oldR * 25173) + 13849) % 65536;
which produces numbers in the range 0 to 65535. The particular numbers in this formula have been shown to give good, random-like, results.
Initially, make the seed value equal to 1. Then, in a more sophisticated program, obtain the milliseconds part of the time using library class Calendar (see Appendix A) to act as the seed.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here