Java Reference
In-Depth Information
by a bit shift, and instead of using the modulus operator % , we can use a bit-
wise and operator. This is because MASK=M-1 consists of the low 48 bits all set
to 1, and a bitwise and operator with MASK thus has the effect of yielding a
48-bit result.
The next routine returns a specified number (at most 32) of random bits
from the computed state, using the high order bits which are more random
than the lower bits. Line 45 is a direct application of the previously stated
linear congruential formula, and line 47 is a bitwise shift (zero-filled in the
high bits to avoid negative numbers). Zero-parameter nextInt obtains 32 bits;
nextLong obtains 64 bits in two separate calls; nextDouble obtains 53 bits (repre-
senting the mantissa; the other 11 bits of a double represent the exponent) also
in two separate calls; and one-parameter nextInt uses a mod operator to obtain
a pseudorandom number in the specified range. The exercises suggest some
improvements that are possible for the one-parameter nextInt , when the param-
eter N is a power of 2.
The 48-bit random number generator (and even the 31-bit generator) is
quite adequate for many applications, simple to implement in 64-bit arithmetic,
and uses little space. However linear congruential generators are unsuitable for
some applications, such as cryptography or in simulations that require large
numbers of highly independent and uncorrelated random numbers.
nonuniform random numbers
9.3
Not all applications require uniformly distributed random numbers. For
example, grades in a large course are generally not uniformly distributed.
Instead, they satisfy the classic bell curve distribution, more formally
known as the normal or Gaussian distribution . A uniform random number
generator can be used to generate random numbers that satisfy other distri-
butions.
An important nonuniform distribution that occurs in simulations is the
Poisson distribution, which models the number of occurrences of a rare
event. Occurrences that happen under the following circumstances satisfy
the Poisson distribution.
The Poisson distri-
bution models the
number of occur-
rences of a rare
event and is used in
simulations.
1.
The probability of one occurrence in a small region is proportional to
the size of the region.
2.
The probability of two occurrences in a small region is proportional
to the square of the size of the region and is usually small enough to
be ignored.
 
 
Search WWH ::




Custom Search