Xoshiro256PlusPlus
implements
interfaces RandomGenerator
and LeapableGenerator
,
and therefore supports methods for producing pseudorandomly chosen
values of type int
, long
, float
, double
,
and boolean
(and for producing streams of pseudorandomly chosen
numbers of type int
, long
, and double
),
as well as methods for creating new Xoshiro256PlusPlus
objects
by moving forward either a large distance (2128) or a very large
distance (2192) around the state cycle.
Series of generated values pass the TestU01 BigCrush and PractRand test suites
that measure independence and uniformity properties of random number generators.
(Most recently validated with
version 1.2.3 of TestU01
and version 0.90 of PractRand.
Note that TestU01 BigCrush was used to test not only values produced by the nextLong()
method but also the result of bit-reversing each value produced by nextLong()
.)
These tests validate only the methods for certain
types and ranges, but similar properties are expected to hold, at
least approximately, for others as well.
The class Xoshiro256PlusPlus
uses the xoshiro256
algorithm,
version 1.0 (parameters 17, 45), with the "++" scrambler that computes
Long.rotateLeft(s0 + s3, 23) + s0
.
(See David Blackman and Sebastiano Vigna, "Scrambled Linear Pseudorandom
Number Generators," ACM Transactions on Mathematical Software, 2021.)
Its state consists of four long
fields x0
, x1
, x2
,
and x3
, which can take on any values provided that they are not all zero.
The period of this generator is 2256-1.
The 64-bit values produced by the nextLong()
method are equidistributed.
To be precise, over the course of the cycle of length 2256-1,
each nonzero long
value is generated 2192 times,
but the value 0 is generated only 2192-1 times.
The values produced by the nextInt()
, nextFloat()
, and nextDouble()
methods are likewise equidistributed.
Moreover, the 64-bit values produced by the nextLong()
method are 3-equidistributed.
Instances Xoshiro256PlusPlus
are not thread-safe.
They are designed to be used so that each thread as its own instance.
The methods jump
and leap
and jumps
and leaps
can be used to construct new instances of Xoshiro256PlusPlus
that traverse
other parts of the state cycle.
Instances of Xoshiro256PlusPlus
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 | Field and Description |
---|---|
private static final AtomicLong | DEFAULT_GEN
The seed generator for default constructors. |
private static final long[] | |
private static final long[] | |
private long | x0
The per-instance state. |
private long | x1
The per-instance state. |
private long | x2
The per-instance state. |
private long | x3
The per-instance state. |
Access | Constructor and Description |
---|---|
public | Xoshiro256PlusPlus(long
first word of the initial state x0, long second word of the initial state x1, long third word of the initial state x2, long fourth word of the initial state x3)Basic constructor that initializes all fields from parameters. |
public | Xoshiro256PlusPlus(long
the initial seed seed)Creates a new instance of |
public | Xoshiro256PlusPlus()
Creates a new instance of |
public | Xoshiro256PlusPlus(byte[]
the initial seed seed)Creates a new instance of |
Modifier and Type | Method and Description |
---|---|
public Xoshiro256PlusPlus | copy()
Implements java. |
public void | jump()
Implements java. |
private void | |
public double | jumpDistance()
Implements java. jump () method will jump forward within
the state cycle of this generator object.
|
public void | leap()
Implements java. |
public double | leapDistance()
Implements java. leap () method will leap forward within
the state cycle of this generator object.
|
public long | nextLong()
Implements java. long value.
|
DEFAULT_GEN | back to summary |
---|---|
private static final AtomicLong DEFAULT_GEN The seed generator for default constructors. |
JUMP_TABLE | back to summary |
---|---|
private static final long[] JUMP_TABLE |
LEAP_TABLE | back to summary |
---|---|
private static final long[] LEAP_TABLE |
x0 | back to summary |
---|---|
private long x0 The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero. |
x1 | back to summary |
---|---|
private long x1 The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero. |
x2 | back to summary |
---|---|
private long x2 The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero. |
x3 | back to summary |
---|---|
private long x3 The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero. |
Xoshiro256PlusPlus | back to summary |
---|---|
public Xoshiro256PlusPlus(long x0, long x1, long x2, long x3) Basic constructor that initializes all fields from parameters. It then adjusts the field values if necessary to ensure that all constraints on the values of fields are met.
|
Xoshiro256PlusPlus | back to summary |
---|---|
public Xoshiro256PlusPlus(long seed) Creates a new instance of
|
Xoshiro256PlusPlus | back to summary |
---|---|
public Xoshiro256PlusPlus() Creates a new instance of |
Xoshiro256PlusPlus | back to summary |
---|---|
public Xoshiro256PlusPlus(byte[] seed) Creates a new instance of
|
copy | back to summary |
---|---|
public Xoshiro256PlusPlus copy() Implements java. Doc from java. Returns a new generator whose internal state is an exact copy of this generator (therefore their future behavior should be identical if subjected to the same series of operations).
|
jump | back to summary |
---|---|
public void jump() Implements java. Doc from java. Alter the state of this pseudorandom number generator so as to jump forward a large, fixed distance (typically 264 or more) within its state cycle.
|
jumpAlgorithm | back to summary |
---|---|
private void jumpAlgorithm(long[] table) |
jumpDistance | back to summary |
---|---|
public double jumpDistance() Implements java. Doc from java. Returns the distance by which the
|
leap | back to summary |
---|---|
public void leap() Implements java. Doc from java. Alter the state of this pseudorandom number generator so as to leap forward a large, fixed distance (typically 296 or more) within its state cycle.
|
leapDistance | back to summary |
---|---|
public double leapDistance() Implements java. Doc from java. Returns the distance by which the
|
nextLong | back to summary |
---|---|
public long nextLong() Implements java. Doc from java. Returns a pseudorandomly chosen
|