Java Reference
In-Depth Information
The low-order bits of linear congruential generators are known to be some-
what nonrandom, so avoid using them. For example, nextInt()%2 is often a
bad way to flip a coin.
4.
When random numbers are being generated in some interval, a common
error is to be slightly off at the boundaries and either allow some number
outside the interval to be generated or not allow the smallest number to be
generated with fair probability.
5.
Many random permutation generators do not generate all permutations
with equal likelihood. As discussed in the text, our algorithm is limited by
the random number generator.
6.
Tinkering with a random number generator is likely to weaken its statisti-
cal properties.
7.
on the internet
Most of the code in this chapter is available.
Random.java
Contains both Random class implementations.
Numerical.java
Contains the primality-testing routine shown in
Figure 9.9 and the math routines presented in Section 7.4.
exercises
IN SHORT
9.1
For the random number generator described in the text, determine the
first 10 values of state , assuming that it is initialized with a value of 1.
Show the result of running the primality-testing algorithm for N = 561
with values of A ranging from 2 to 5.
9.2
If 42,000,000 lottery tickets are sold (with 14,000,000 to 1 odds of a
ticket being a winner), what is the expected number of winners? What
are the odds that there will be no winners? One winner?
9.3
Why can't zero be used as a seed for the linear congruential
generator?
9.4
IN THEORY
9.5
Prove that Equation 9.4 is equivalent to Equation 9.1 and that the
resulting program in Figure 9.2 is correct.
Complete the proof that each permutation obtained in Figure 9.7 is
equally likely.
9.6
 
Search WWH ::




Custom Search