Package it.unimi.dsi.util
Class SplitMix64RandomGenerator
- java.lang.Object
-
- org.apache.commons.math3.random.AbstractRandomGenerator
-
- it.unimi.dsi.util.SplitMix64RandomGenerator
-
- All Implemented Interfaces:
java.io.Serializable
,org.apache.commons.math3.random.RandomGenerator
public class SplitMix64RandomGenerator extends org.apache.commons.math3.random.AbstractRandomGenerator implements java.io.Serializable
A fast, high-quality, non-splittable version of the SplitMix pseudorandom number generator used bySplittableRandom
. Due to the fixed increment constant and to different strategies in generating finite ranges, the methods of this generator are usually faster than those ofSplittableRandom
.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:
it.unimi.dsi.util
,RandomGenerator
,SplitMix64Random
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SplitMix64RandomGenerator()
Creates a new generator seeded usingUtil.randomSeed()
.SplitMix64RandomGenerator(long seed)
Creates a new generator using a given seed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
nextBoolean()
void
nextBytes(byte[] bytes)
double
nextDouble()
float
nextFloat()
int
nextInt()
int
nextInt(int n)
long
nextLong()
long
nextLong(long n)
Returns a pseudorandom uniformly distributedlong
value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.void
setSeed(long seed)
Sets the seed of this generator.void
setState(long state)
Sets the state of this generator.
-
-
-
Constructor Detail
-
SplitMix64RandomGenerator
public SplitMix64RandomGenerator()
Creates a new generator seeded usingUtil.randomSeed()
.
-
SplitMix64RandomGenerator
public SplitMix64RandomGenerator(long seed)
Creates a new generator using a given seed.- Parameters:
seed
- a seed for the generator.
-
-
Method Detail
-
nextLong
public long nextLong()
- Specified by:
nextLong
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextLong
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextInt
public int nextInt()
- Specified by:
nextInt
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextInt
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextInt
public int nextInt(int n)
- Specified by:
nextInt
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextInt
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextLong
public long nextLong(long n)
Returns a pseudorandom uniformly distributedlong
value 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
long
value between0
(inclusive) andn
(exclusive).
-
nextDouble
public double nextDouble()
- Specified by:
nextDouble
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Specified by:
nextDouble
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextFloat
public float nextFloat()
- Specified by:
nextFloat
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextFloat
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextBoolean
public boolean nextBoolean()
- Specified by:
nextBoolean
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextBoolean
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
nextBytes
public void nextBytes(byte[] bytes)
- Specified by:
nextBytes
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Overrides:
nextBytes
in classorg.apache.commons.math3.random.AbstractRandomGenerator
-
setSeed
public void setSeed(long seed)
Sets the seed of this generator.The seed will be passed through
HashCommon.murmurHash3(long)
.- Specified by:
setSeed
in interfaceorg.apache.commons.math3.random.RandomGenerator
- Specified by:
setSeed
in classorg.apache.commons.math3.random.AbstractRandomGenerator
- Parameters:
seed
- a seed for this generator.
-
setState
public void setState(long state)
Sets the state of this generator.- Parameters:
state
- the new state for this generator (must be nonzero).
-
-