public final class SplittableRandom extends Object
SplittableRandom
supports methods for
producing pseudorandom numbers of type int
, long
,
and double
with similar usages as for class
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/joinstyle
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 SecureRandom
in securitysensitive applications. Additionally,
defaultconstructed instances do not use a cryptographically random
seed unless the system property
java.util.secureRandomSeed
is set to true
.
Constructor  Description 

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.

SplittableRandom(long seed) 
Creates a new SplittableRandom instance using the specified
initial seed.

Modifier and Type  Method  Description 

DoubleStream 
doubles() 
Returns an effectively unlimited stream of pseudorandom
double values from this generator and/or one split from it; each value
is between zero (inclusive) and one (exclusive). 
DoubleStream 
doubles(double randomNumberOrigin,
double randomNumberBound) 
Returns an effectively unlimited stream of pseudorandom
double values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive). 
DoubleStream 
doubles(long streamSize) 
Returns a stream producing the given
streamSize number of
pseudorandom double values from this generator and/or one split
from it; each value is between zero (inclusive) and one (exclusive). 
DoubleStream 
doubles(long streamSize,
double randomNumberOrigin,
double randomNumberBound) 
Returns a stream producing the given
streamSize number of
pseudorandom double values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive). 
IntStream 
ints() 
Returns an effectively unlimited stream of pseudorandom
int
values from this generator and/or one split from it. 
IntStream 
ints(int randomNumberOrigin,
int randomNumberBound) 
Returns an effectively unlimited stream of pseudorandom
int values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive). 
IntStream 
ints(long streamSize) 
Returns a stream producing the given
streamSize number
of pseudorandom int values from this generator and/or
one split from it. 
IntStream 
ints(long streamSize,
int randomNumberOrigin,
int randomNumberBound) 
Returns a stream producing the given
streamSize number
of pseudorandom int values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive). 
LongStream 
longs() 
Returns an effectively unlimited stream of pseudorandom
long values from this generator and/or one split from it. 
LongStream 
longs(long streamSize) 
Returns a stream producing the given
streamSize number
of pseudorandom long values from this generator and/or
one split from it. 
LongStream 
longs(long randomNumberOrigin,
long randomNumberBound) 
Returns an effectively unlimited stream of pseudorandom
long values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive). 
LongStream 
longs(long streamSize,
long randomNumberOrigin,
long randomNumberBound) 
Returns a stream producing the given
streamSize number of
pseudorandom long values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive). 
boolean 
nextBoolean() 
Returns a pseudorandom
boolean value. 
double 
nextDouble() 
Returns a pseudorandom
double value between zero
(inclusive) and one (exclusive). 
double 
nextDouble(double bound) 
Returns a pseudorandom
double value between 0.0
(inclusive) and the specified bound (exclusive). 
double 
nextDouble(double origin,
double bound) 
Returns a pseudorandom
double value between the specified
origin (inclusive) and bound (exclusive). 
int 
nextInt() 
Returns a pseudorandom
int value. 
int 
nextInt(int bound) 
Returns a pseudorandom
int value between zero (inclusive)
and the specified bound (exclusive). 
int 
nextInt(int origin,
int bound) 
Returns a pseudorandom
int value between the specified
origin (inclusive) and the specified bound (exclusive). 
long 
nextLong() 
Returns a pseudorandom
long value. 
long 
nextLong(long bound) 
Returns a pseudorandom
long value between zero (inclusive)
and the specified bound (exclusive). 
long 
nextLong(long origin,
long bound) 
Returns a pseudorandom
long value between the specified
origin (inclusive) and the specified bound (exclusive). 
SplittableRandom 
split() 
Constructs and returns a new SplittableRandom instance that
shares no mutable state with this instance.

public SplittableRandom(long seed)
seed
 the initial seedpublic SplittableRandom()
public SplittableRandom split()
split()
method,
and the same expected statistical properties apply to the
entire set of generators constructed by such recursive
splitting.public int nextInt()
int
value.int
valuepublic int nextInt(int bound)
int
value between zero (inclusive)
and the specified bound (exclusive).bound
 the upper bound (exclusive). Must be positive.int
value between zero
(inclusive) and the bound (exclusive)IllegalArgumentException
 if bound
is not positivepublic int nextInt(int origin, int bound)
int
value between the specified
origin (inclusive) and the specified bound (exclusive).origin
 the least value returnedbound
 the upper bound (exclusive)int
value between the origin
(inclusive) and the bound (exclusive)IllegalArgumentException
 if origin
is greater than
or equal to bound
public long nextLong()
long
value.long
valuepublic long nextLong(long bound)
long
value between zero (inclusive)
and the specified bound (exclusive).bound
 the upper bound (exclusive). Must be positive.long
value between zero
(inclusive) and the bound (exclusive)IllegalArgumentException
 if bound
is not positivepublic long nextLong(long origin, long bound)
long
value between the specified
origin (inclusive) and the specified bound (exclusive).origin
 the least value returnedbound
 the upper bound (exclusive)long
value between the origin
(inclusive) and the bound (exclusive)IllegalArgumentException
 if origin
is greater than
or equal to bound
public double nextDouble()
double
value between zero
(inclusive) and one (exclusive).double
value between zero
(inclusive) and one (exclusive)public double nextDouble(double bound)
double
value between 0.0
(inclusive) and the specified bound (exclusive).bound
 the upper bound (exclusive). Must be positive.double
value between zero
(inclusive) and the bound (exclusive)IllegalArgumentException
 if bound
is not positivepublic double nextDouble(double origin, double bound)
double
value between the specified
origin (inclusive) and bound (exclusive).origin
 the least value returnedbound
 the upper bound (exclusive)double
value between the origin
(inclusive) and the bound (exclusive)IllegalArgumentException
 if origin
is greater than
or equal to bound
public boolean nextBoolean()
boolean
value.boolean
valuepublic IntStream ints(long streamSize)
streamSize
number
of pseudorandom int
values from this generator and/or
one split from it.streamSize
 the number of values to generateint
valuesIllegalArgumentException
 if streamSize
is
less than zeropublic IntStream ints()
int
values from this generator and/or one split from it.int
values
ints(Long.MAX_VALUE)
.public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound)
streamSize
number
of pseudorandom int
values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive).streamSize
 the number of values to generaterandomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valueint
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if streamSize
is
less than zero, or randomNumberOrigin
is greater than or equal to randomNumberBound
public IntStream ints(int randomNumberOrigin, int randomNumberBound)
int
values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive).randomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valueint
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if randomNumberOrigin
is greater than or equal to randomNumberBound
ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)
.public LongStream longs(long streamSize)
streamSize
number
of pseudorandom long
values from this generator and/or
one split from it.streamSize
 the number of values to generatelong
valuesIllegalArgumentException
 if streamSize
is
less than zeropublic LongStream longs()
long
values from this generator and/or one split from it.long
values
longs(Long.MAX_VALUE)
.public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound)
streamSize
number of
pseudorandom long
values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive).streamSize
 the number of values to generaterandomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valuelong
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if streamSize
is
less than zero, or randomNumberOrigin
is greater than or equal to randomNumberBound
public LongStream longs(long randomNumberOrigin, long randomNumberBound)
long
values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive).randomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valuelong
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if randomNumberOrigin
is greater than or equal to randomNumberBound
longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)
.public DoubleStream doubles(long streamSize)
streamSize
number of
pseudorandom double
values from this generator and/or one split
from it; each value is between zero (inclusive) and one (exclusive).streamSize
 the number of values to generatedouble
valuesIllegalArgumentException
 if streamSize
is
less than zeropublic DoubleStream doubles()
double
values from this generator and/or one split from it; each value
is between zero (inclusive) and one (exclusive).double
values
doubles(Long.MAX_VALUE)
.public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)
streamSize
number of
pseudorandom double
values from this generator and/or one split
from it; each value conforms to the given origin (inclusive) and bound
(exclusive).streamSize
 the number of values to generaterandomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valuedouble
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if streamSize
is
less than zero, or randomNumberOrigin
is greater than or equal to randomNumberBound
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
double
values from this generator and/or one split from it; each value
conforms to the given origin (inclusive) and bound (exclusive).randomNumberOrigin
 the origin (inclusive) of each random valuerandomNumberBound
 the bound (exclusive) of each random valuedouble
values,
each with the given origin (inclusive) and bound (exclusive)IllegalArgumentException
 if randomNumberOrigin
is greater than or equal to randomNumberBound
doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)
.