Package it.unimi.dsi.util
Class SplitMix64Random
java.lang.Object
java.util.Random
it.unimi.dsi.util.SplitMix64Random
- All Implemented Interfaces:
Serializable,java.util.random.RandomGenerator
A fast, high-quality, non-splittable version of the SplitMix
pseudorandom number generator used by
SplittableRandom. Due to
the fixed increment constant and to different strategies in generating finite ranges, the methods of this generator
are usually faster than those of SplittableRandom.
Note that this generator has a relatively short period (264) so it should not be used to generate very long sequences (the rule of thumb to have a period greater than the square of the length of the sequence you want to generate).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.SplittableGenerator, java.util.random.RandomGenerator.StreamableGenerator -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new generator seeded usingUtil.randomSeed().SplitMix64Random(long seed) Creates a new generator using a given seed. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidnextBytes(byte[] bytes) doublefloatintnextInt()intnextInt(int n) longnextLong()longnextLong(long n) Returns a pseudorandom uniformly distributedlongvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.voidsetSeed(long seed) Sets the seed of this generator.voidsetState(long state) Sets the state of this generator.Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, next, nextGaussianMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong
-
Constructor Details
-
SplitMix64Random
public SplitMix64Random()Creates a new generator seeded usingUtil.randomSeed(). -
SplitMix64Random
public SplitMix64Random(long seed) Creates a new generator using a given seed.- Parameters:
seed- a seed for the generator.
-
-
Method Details
-
nextLong
public long nextLong() -
nextInt
public int nextInt() -
nextInt
public int nextInt(int n) -
nextLong
public long nextLong(long n) Returns a pseudorandom uniformly distributedlongvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The algorithm used to generate the value guarantees that the result is uniform, provided that the sequence of 64-bit values produced by this generator is.- Parameters:
n- the positive bound on the random number to be returned.- Returns:
- the next pseudorandom
longvalue between0(inclusive) andn(exclusive).
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfacejava.util.random.RandomGenerator- Overrides:
nextDoublein classRandom
-
nextFloat
public float nextFloat() -
nextBoolean
public boolean nextBoolean()- Specified by:
nextBooleanin interfacejava.util.random.RandomGenerator- Overrides:
nextBooleanin classRandom
-
nextBytes
public void nextBytes(byte[] bytes) -
setSeed
public void setSeed(long seed) Sets the seed of this generator.The seed will be passed through
HashCommon.murmurHash3(long). -
setState
public void setState(long state) Sets the state of this generator.- Parameters:
state- the new state for this generator (must be nonzero).
-