Package squidpony.squidmath
Class RNG.CustomRandom
java.lang.Object
java.util.Random
squidpony.squidmath.RNG.CustomRandom
- All Implemented Interfaces:
Serializable
- Enclosing class:
- RNG
public static class RNG.CustomRandom extends Random
A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
- Author:
- Tommy Ettinger
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description CustomRandom()
Creates a new random number generator.CustomRandom(RandomnessSource randomnessSource)
Creates a new random number generator. -
Method Summary
-
Constructor Details
-
CustomRandom
public CustomRandom()Creates a new random number generator. This constructor uses a DiverRNG with a random seed. -
CustomRandom
Creates a new random number generator. This constructor uses the seed of the given RandomnessSource if it has been seeded.- Parameters:
randomnessSource
- a way to get random bits, supplied by RNG
-
-
Method Details
-
next
Generates the next pseudorandom number. Subclasses should override this, as this is used by all other methods.The general contract of
next
is that it returns anint
value and if the argumentbits
is between1
and32
(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 be0
or1
. The methodnext
is implemented by classRandom
by atomically updating the seed to
and returning(seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)
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.(int)(seed >>> (48 - bits))
. -
nextLong
Returns the next pseudorandom, uniformly distributedlong
value from this random number generator's sequence. The general contract ofnextLong
is that onelong
value is pseudorandomly generated and returned.
-