public static class RNG.CustomRandom
extends java.util.Random
Constructor and Description |
---|
CustomRandom()
Creates a new random number generator.
|
CustomRandom(RandomnessSource randomnessSource)
Creates a new random number generator.
|
Modifier and Type | Method and Description |
---|---|
protected int |
next(int bits)
Generates the next pseudorandom number.
|
long |
nextLong()
Returns the next pseudorandom, uniformly distributed
long
value from this random number generator's sequence. |
public CustomRandom()
public CustomRandom(RandomnessSource randomnessSource)
randomnessSource
- a way to get random bits, supplied by RNGprotected int next(int bits)
The general contract of next
is that it returns an
int
value and if the argument bits
is between
1
and 32
(inclusive), then that many low-order
bits of the returned value will be (approximately) independently
chosen bit values, each of which is (approximately) equally
likely to be 0
or 1
. The method next
is
implemented by class Random
by atomically updating the seed to
(seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)
and returning
(int)(seed >>> (48 - bits))
.
This is a linear congruential pseudorandom number generator, as
defined by D. H. Lehmer and described by Donald E. Knuth in
The Art of Computer Programming, Volume 3:
Seminumerical Algorithms, section 3.2.1.next
in class java.util.Random
bits
- random bitspublic long nextLong()
long
value from this random number generator's sequence. The general
contract of nextLong
is that one long
value is
pseudorandomly generated and returned.nextLong
in class java.util.Random
long
value from this random number generator's sequenceCopyright © Eben Howard 2012–2022. All rights reserved.