Class XoShiRo256StarStarRandom
- java.lang.Object
-
- java.util.Random
-
- it.unimi.dsi.util.XoShiRo256StarStarRandom
-
- All Implemented Interfaces:
Serializable
public class XoShiRo256StarStarRandom extends Random
A fast, all-purpose, rock-solid pseudorandom number generator. It has excellent speed, a state space (256 bits) that is large enough for any parallel application, and it passes all tests we are aware of. In Java, it is slightly slower than aXoShiRo256PlusPlusRandom. More information can be found at our PRNG page.If you need to generate just floating-point numbers,
XoShiRo256PlusRandomis slightly faster. If you are tight on space, you might tryXoRoShiRo128StarStarRandom.By using the supplied
jump()method it is possible to generate non-overlapping long sequences for parallel computations;longJump()makes it possible to create several starting points, each providing several non-overlapping sequences, for distributed computations. This class provides also asplit()method to support recursive parallel computations, in the spirit ofSplittableRandom.Note that this is not a secure generator.
- Version:
- 1.0
- See Also:
it.unimi.dsi.util,RandomGenerator,XoShiRo256StarStarRandomGenerator, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description XoShiRo256StarStarRandom()Creates a new generator seeded usingUtil.randomSeed().XoShiRo256StarStarRandom(long seed)Creates a new generator using a given seed.
-
Method Summary
Modifier and Type Method Description XoShiRo256StarStarRandomjump()The jump function for this generator.XoShiRo256StarStarRandomlongJump()The long-jump function for this generator.static voidmain(String[] arg)booleannextBoolean()voidnextBytes(byte[] bytes)doublenextDouble()doublenextDoubleFast()Returns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence, using a fast multiplication-free method which, however, can provide only 52 significant bits.floatnextFloat()intnextInt()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.XoShiRo256StarStarRandomsplit()Returns a new instance that shares no mutable state with this instance.
-
-
-
Constructor Detail
-
XoShiRo256StarStarRandom
public XoShiRo256StarStarRandom()
Creates a new generator seeded usingUtil.randomSeed().
-
XoShiRo256StarStarRandom
public XoShiRo256StarStarRandom(long seed)
Creates a new generator using a given seed.- Parameters:
seed- a seed for the generator.
-
-
Method Detail
-
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()
- Overrides:
nextDoublein classRandom
-
nextDoubleFast
public double nextDoubleFast()
Returns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence, using a fast multiplication-free method which, however, can provide only 52 significant bits.This method is faster than
nextDouble(), but it can return only dyadic rationals of the form k / 2−52, instead of the standard k / 2−53. Before version 2.4.1, this was actually the standard implementation ofnextDouble(), so you can use this method if you need to reproduce exactly results obtained using previous versions.The only difference between the output of this method and that of
nextDouble()is an additional least significant bit set in half of the returned values. For most applications, this difference is negligible.- Returns:
- the next pseudorandom, uniformly distributed
doublevalue between0.0and1.0from this random number generator's sequence, using 52 significant bits only.
-
nextBoolean
public boolean nextBoolean()
- Overrides:
nextBooleanin classRandom
-
jump
public XoShiRo256StarStarRandom jump()
The jump function for this generator. It is equivalent to 2128 calls tonextLong(); it can be used to generate 2128 non-overlapping subsequences for parallel computations.- Returns:
- this generator.
- See Also:
#copy()
-
longJump
public XoShiRo256StarStarRandom longJump()
The long-jump function for this generator. It is equivalent to 2192 calls tonextLong(); it can be used to generate 264 starting points, from each of whichjump()will generate 264 non-overlapping subsequences for parallel distributed computations.- Returns:
- this generator.
- See Also:
#copy()
-
split
public XoShiRo256StarStarRandom split()
Returns a new instance that shares no mutable state with this instance. The sequence generated by the new instance depends deterministically from the state of this instance, but the probability that the sequence generated by this instance and by the new instance overlap is negligible.- Returns:
- the new instance.
-
setSeed
public void setSeed(long seed)
Sets the seed of this generator.The argument will be used to seed a
SplitMix64RandomGenerator, whose output will in turn be used to seed this generator. This approach makes “warmup” unnecessary, and makes the probability of starting from a state with a large fraction of bits set to zero astronomically small.
-
setState
public void setState(long[] state)
Sets the state of this generator.The internal state of the generator will be reset, and the state array filled with the provided array.
- Parameters:
state- an array of 2 longs; at least one must be nonzero.
-
main
public static void main(String[] arg)
-
-