Class DefaultRandom
- All Implemented Interfaces:
Serializable
DefaultRandom()
constructor, or
use the static getInstance(long)
method in class Random.
Class DefaultRandom generates random numbers by hashing successive counter values. The seed initializes the counter. The hash function is defined in W. Press et al., Numerical Recipes: The Art of Scientific Computing, Third Edition (Cambridge University Press, 2007), page 352. The hash function applied to the counter value i is:
x := 3935559000370003845 * i + 2691343689449507681 (mod
264)
x := x xor (x right-shift 21)
x := x xor (x left-shift 37)
x := x xor (x right-shift 4)
x := 4768777513237032717 * x (mod 264)
x := x xor (x left-shift 20)
x := x xor (x right-shift 41)
x := x xor (x left-shift 5)
Return x
(The shift and arithmetic operations are all performed on unsigned 64-bit numbers.)
- Version:
- 30-Mar-2008
- Author:
- Alan Kaminsky
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected long
next()
Return the next 64-bit pseudorandom value in this PRNG's sequence.protected long
next
(long skip) Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence.void
setSeed
(long seed) Set this PRNG's seed.Methods inherited from class edu.rit.util.Random
getInstance, getInstance, nextBoolean, nextBoolean, nextByte, nextByte, nextCharacter, nextCharacter, nextDouble, nextDouble, nextFloat, nextFloat, nextInt, nextInt, nextInteger, nextInteger, nextLong, nextLong, nextShort, nextShort, nextUnsignedByte, nextUnsignedByte, nextUnsignedShort, nextUnsignedShort, skip, skip
-
Constructor Details
-
DefaultRandom
public DefaultRandom(long seed) Construct a new PRNG with the given seed. Any seed value is allowed.- Parameters:
seed
- Seed.
-
-
Method Details
-
setSeed
public void setSeed(long seed) Set this PRNG's seed.Note: Depending on the PRNG algorithm, certain seed values may not be allowed. See the PRNG algorithm subclass for further information. Set this PRNG's seed. Any seed value is allowed.
-
next
protected long next()Return the next 64-bit pseudorandom value in this PRNG's sequence. -
next
protected long next(long skip) Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence. Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence.
-