SplittableRandom
supports methods for producing pseudorandom numbers of type int,
long, and double with similar usages as for class
java.util.Random but differs in the following ways:
split constructs and returns a new
SplittableRandom instance that shares no mutable state with the
current instance. However, with very high probability, the
values collectively generated by the two objects have the same
statistical properties as if the same quantity of values were
generated by a single thread using a single SplittableRandom object. fork/join-style computation using random numbers might include a
construction of the form new
Subtask(aSplittableRandom.split()).fork().
stream.parallel() mode.Instances of SplittableRandom are not cryptographically
secure. Consider instead using java.
in security-sensitive applications. Additionally,
default-constructed instances do not use a cryptographically random
seed unless the system property
java.util.secureRandomSeed is set to true.
| Modifier and Type | Class and Description |
|---|---|
| private class | SplittableRandom.
Proxy class to non-public RandomSupportAbstractSplittableGenerator. |
| Modifier and Type | Field and Description |
|---|---|
| private static final AtomicLong | defaultGen
The seed generator for default constructors. |
| private final long | gamma
The step value. |
| private static final long | GOLDEN_GAMMA
The golden ratio scaled to 64bits, used as the initial gamma value for (unsplit) SplittableRandoms. |
| private SplittableRandom. | proxy
Proxy object to non-public RandomSupportAbstractSplittableGenerator. |
| private long | seed
The seed. |
| Access | Constructor and Description |
|---|---|
| private | SplittableRandom(long seed, long gamma)
Internal constructor used by all others except default constructor. |
| public | SplittableRandom(long
the initial seed seed)Creates a new SplittableRandom instance using the specified initial seed. |
| public | SplittableRandom()
Creates a new SplittableRandom instance that is likely to generate sequences of values that are statistically independent of those of any other instances in the current program; and may, and typically does, vary across program invocations. |
| Modifier and Type | Method and Description |
|---|---|
| public DoubleStream | Returns: a stream ofdouble valuesthe number of values to generate streamSize)Overrides default java. Returns a stream producing the given |
| public DoubleStream | Returns: a stream of pseudorandomdouble valuesOverrides default java. Returns an effectively unlimited stream of pseudorandom |
| public DoubleStream | Returns: a stream of pseudorandomdouble values,
each with the given origin (inclusive) and bound (exclusive)the number of values to generate streamSize, double the origin (inclusive) of each random value randomNumberOrigin, double the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns a stream producing the given |
| public DoubleStream | Returns: a stream of pseudorandomdouble values,
each with the given origin (inclusive) and bound (exclusive)the origin (inclusive) of each random value randomNumberOrigin, double the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns an effectively unlimited stream of pseudorandom |
| public IntStream | Returns: a stream of pseudorandomint valuesthe number of values to generate streamSize)Overrides default java. Returns a stream producing the given |
| public IntStream | Returns: a stream of pseudorandomint valuesOverrides default java. Returns an effectively unlimited stream of pseudorandom |
| public IntStream | Returns: a stream of pseudorandomint values,
each with the given origin (inclusive) and bound (exclusive)the number of values to generate streamSize, int the origin (inclusive) of each random value randomNumberOrigin, int the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns a stream producing the given |
| public IntStream | Returns: a stream of pseudorandomint values,
each with the given origin (inclusive) and bound (exclusive)the origin (inclusive) of each random value randomNumberOrigin, int the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns an effectively unlimited stream of pseudorandom |
| public LongStream | Returns: a stream of pseudorandomlong valuesthe number of values to generate streamSize)Overrides default java. Returns a stream producing the given |
| public LongStream | Returns: a stream of pseudorandomlong valuesOverrides default java. Returns an effectively unlimited stream of pseudorandom |
| public LongStream | Returns: a stream of pseudorandomlong values,
each with the given origin (inclusive) and bound (exclusive)the number of values to generate streamSize, long the origin (inclusive) of each random value randomNumberOrigin, long the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns a stream producing the given |
| public LongStream | Returns: a stream of pseudorandomlong values,
each with the given origin (inclusive) and bound (exclusive)the origin (inclusive) of each random value randomNumberOrigin, long the bound (exclusive) of each random value randomNumberBound)Overrides default java. Returns an effectively unlimited stream of pseudorandom |
| private static int | |
| private static long | |
| private static long | |
| public void | nextBytes(byte[] bytes)
Overrides default java. Fills a user-supplied byte array with generated byte values pseudorandomly chosen uniformly from the range of values between -128 (inclusive) and 127 (inclusive). |
| public int | nextInt()
Overrides default java. Returns a pseudorandomly chosen |
| public long | nextLong()
Implements java. Returns a pseudorandomly chosen |
| private long | |
| public SplittableRandom | Returns: the new SplittableRandom instanceImplements java. Constructs and returns a new SplittableRandom instance that shares no mutable state with this instance. |
| public SplittableRandom | split(RandomGenerator.
Implements java. Returns a new pseudorandom number generator, split off from this one,
that implements the |
| public Stream | splits()
Overrides default java. Returns an effectively unlimited stream of new pseudorandom number
generators, each of which implements the |
| public Stream | splits(long streamSize)
Implements java. Returns a stream producing the given |
| public Stream | splits(RandomGenerator.
Implements java. Returns an effectively unlimited stream of new pseudorandom number
generators, each of which implements the |
| public Stream | splits(long streamSize, RandomGenerator.
Implements java. Returns a stream producing the given |
| defaultGen | back to summary |
|---|---|
| private static final AtomicLong defaultGen The seed generator for default constructors. | |
| gamma | back to summary |
|---|---|
| private final long gamma The step value. | |
| GOLDEN_GAMMA | back to summary |
|---|---|
| private static final long GOLDEN_GAMMA The golden ratio scaled to 64bits, used as the initial gamma value for (unsplit) SplittableRandoms. | |
| proxy | back to summary |
|---|---|
| private SplittableRandom. Proxy object to non-public RandomSupportAbstractSplittableGenerator. | |
| seed | back to summary |
|---|---|
| private long seed The seed. Updated only via method nextSeed. | |
| SplittableRandom | back to summary |
|---|---|
| private SplittableRandom(long seed, long gamma) Internal constructor used by all others except default constructor. | |
| SplittableRandom | back to summary |
|---|---|
| public SplittableRandom(long seed) Creates a new SplittableRandom instance using the specified initial seed. SplittableRandom instances created with the same seed in the same program generate identical sequences of values.
| |
| SplittableRandom | back to summary |
|---|---|
| public SplittableRandom() Creates a new SplittableRandom instance that is likely to generate sequences of values that are statistically independent of those of any other instances in the current program; and may, and typically does, vary across program invocations. | |
| doubles | back to summary |
|---|---|
| public DoubleStream doubles(long streamSize) Overrides default java. Returns a stream producing the given
| |
| doubles | back to summary |
|---|---|
| public DoubleStream doubles() Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to
| |
| doubles | back to summary |
|---|---|
| public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) Overrides default java. Returns a stream producing the given
| |
| doubles | back to summary |
|---|---|
| public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to
| |
| ints | back to summary |
|---|---|
| public IntStream ints(long streamSize) Overrides default java. Returns a stream producing the given
| |
| ints | back to summary |
|---|---|
| public IntStream ints() Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to | |
| ints | back to summary |
|---|---|
| public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) Overrides default java. Returns a stream producing the given
| |
| ints | back to summary |
|---|---|
| public IntStream ints(int randomNumberOrigin, int randomNumberBound) Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to
| |
| longs | back to summary |
|---|---|
| public LongStream longs(long streamSize) Overrides default java. Returns a stream producing the given
| |
| longs | back to summary |
|---|---|
| public LongStream longs() Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to
| |
| longs | back to summary |
|---|---|
| public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) Overrides default java. Returns a stream producing the given
| |
| longs | back to summary |
|---|---|
| public LongStream longs(long randomNumberOrigin, long randomNumberBound) Overrides default java. Returns an effectively unlimited stream of pseudorandom Implementation Note This method is implemented to be equivalent to
| |
| mix32 | back to summary |
|---|---|
| private static int mix32(long z) Returns the 32 high bits of Stafford variant 4 mix64 function as int. http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html | |
| mix64 | back to summary |
|---|---|
| private static long mix64(long z) Computes Stafford variant 13 of 64bit mix function. http://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html | |
| mixGamma | back to summary |
|---|---|
| private static long mixGamma(long z) Returns the gamma value to use for a new split instance. Uses the 64bit mix function from MurmurHash3. https://github.com/aappleby/smhasher/wiki/MurmurHash3 | |
| nextBytes | back to summary |
|---|---|
| public void nextBytes(byte[] bytes) Overrides default java. Doc from java. Fills a user-supplied byte array with generated byte values pseudorandomly chosen uniformly from the range of values between -128 (inclusive) and 127 (inclusive).
| |
| nextInt | back to summary |
|---|---|
| public int nextInt() Overrides default java. Doc from java. Returns a pseudorandomly chosen
| |
| nextLong | back to summary |
|---|---|
| public long nextLong() Implements java. Doc from java. Returns a pseudorandomly chosen
| |
| nextSeed | back to summary |
|---|---|
| private long nextSeed() Adds gamma to seed. | |
| split | back to summary |
|---|---|
| public SplittableRandom split() Implements java. Constructs and returns a new SplittableRandom instance that
shares no mutable state with this instance. However, with very
high probability, the set of values collectively generated by
the two objects has the same statistical properties as if the
same quantity of values were generated by a single thread using
a single SplittableRandom object. Either or both of the two
objects may be further split using the
| |
| split | back to summary |
|---|---|
| public SplittableRandom split(RandomGenerator. Implements java. Doc from java. Returns a new pseudorandom number generator, split off from this one,
that implements the
| |
| splits | back to summary |
|---|---|
| public Stream Overrides default java. Doc from java. Returns an effectively unlimited stream of new pseudorandom number
generators, each of which implements the This pseudorandom number generator may be used as a source of pseudorandom bits used to initialize the state the new ones. Implementation Specification The default implementation invokes
| |
| splits | back to summary |
|---|---|
| public Stream Implements java. Doc from java. Returns a stream producing the given This pseudorandom number generator may be used as a source of pseudorandom bits used to initialize the state the new ones.
| |
| splits | back to summary |
|---|---|
| public Stream Implements java. Doc from java. Returns an effectively unlimited stream of new pseudorandom number
generators, each of which implements the Implementation Specification It is permitted to implement this method in a manner
equivalent to
| |
| splits | back to summary |
|---|---|
| public Stream Implements java. Doc from java. Returns a stream producing the given
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | nextInt()
Overrides default java. Returns a pseudorandomly chosen |
| public long | nextLong()
Implements java. Returns a pseudorandomly chosen |
| public SplittableRandom | split(RandomGenerator.
Implements java. Returns a new pseudorandom number generator, split off from this one,
that implements the |
| AbstractSplittableGeneratorProxy | back to summary |
|---|---|
| private AbstractSplittableGeneratorProxy() | |
| nextInt | back to summary |
|---|---|
| public int nextInt() Overrides default java. Doc from java. Returns a pseudorandomly chosen
| |
| nextLong | back to summary |
|---|---|
| public long nextLong() Implements java. Doc from java. Returns a pseudorandomly chosen
| |
| split | back to summary |
|---|---|
| public SplittableRandom split(RandomGenerator. Implements java. Doc from java. Returns a new pseudorandom number generator, split off from this one,
that implements the
| |