Top Description Fields Constructors Methods
jdk.random

public final Class Xoshiro256PlusPlus

extends Object
implements LeapableGenerator
Class Inheritance
All Implemented Interfaces
java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.StreamableGenerator, java.util.random.RandomGenerator
Annotations
@RandomGeneratorProperties
name:Xoshiro256PlusPlus
group:Xoshiro
i:256
j:1
k:0
equidistribution:3
Imports
java.util.concurrent.atomic.AtomicLong, java.util.random.RandomGenerator, .RandomGenerator.LeapableGenerator, jdk.internal.util.random.RandomSupport, .RandomSupport.RandomGeneratorProperties

A "jumpable and leapable" pseudorandom number generator (PRNG) whose period is roughly 2256. Class 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.security.SecureRandom 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.

Since
17

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor 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 Xoshiro256PlusPlus using the specified long value as the initial seed.

public
Xoshiro256PlusPlus()

Creates a new instance of Xoshiro256PlusPlus that is likely to generate sequences of values that are statistically independent of those of any other instances in the current program execution, but may, and typically does, vary across program invocations.

public
Xoshiro256PlusPlus(byte[]
the initial seed
seed
)

Creates a new instance of Xoshiro256PlusPlus using the specified array of initial seed bytes.

Method Summary

Modifier and TypeMethod and Description
public Xoshiro256PlusPlus
copy()

Implements java.util.random.RandomGenerator.LeapableGenerator.copy.

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).
public void
jump()

Implements java.util.random.RandomGenerator.JumpableGenerator.jump.

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.
private void
jumpAlgorithm(long[] table)

public double
jumpDistance()

Implements java.util.random.RandomGenerator.JumpableGenerator.jumpDistance.

Returns the distance by which the jump() method will jump forward within the state cycle of this generator object.
public void
leap()

Implements java.util.random.RandomGenerator.LeapableGenerator.leap.

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.
public double
leapDistance()

Implements java.util.random.RandomGenerator.LeapableGenerator.leapDistance.

Returns the distance by which the leap() method will leap forward within the state cycle of this generator object.
public long
nextLong()

Implements java.util.random.RandomGenerator.nextLong.

Returns a pseudorandomly chosen long value.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_GENback to summary
private static final AtomicLong DEFAULT_GEN

The seed generator for default constructors.

JUMP_TABLEback to summary
private static final long[] JUMP_TABLE
LEAP_TABLEback to summary
private static final long[] LEAP_TABLE
x0back to summary
private long x0

The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero.

x1back to summary
private long x1

The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero.

x2back to summary
private long x2

The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero.

x3back to summary
private long x3

The per-instance state. At least one of the four fields x0, x1, x2, and x3 must be nonzero.

Constructor Detail

Xoshiro256PlusPlusback 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.

Parameters
x0:long

first word of the initial state

x1:long

second word of the initial state

x2:long

third word of the initial state

x3:long

fourth word of the initial state

Xoshiro256PlusPlusback to summary
public Xoshiro256PlusPlus(long seed)

Creates a new instance of Xoshiro256PlusPlus using the specified long value as the initial seed. Instances of Xoshiro256PlusPlus created with the same seed in the same program generate identical sequences of values.

Parameters
seed:long

the initial seed

Xoshiro256PlusPlusback to summary
public Xoshiro256PlusPlus()

Creates a new instance of Xoshiro256PlusPlus that is likely to generate sequences of values that are statistically independent of those of any other instances in the current program execution, but may, and typically does, vary across program invocations.

Xoshiro256PlusPlusback to summary
public Xoshiro256PlusPlus(byte[] seed)

Creates a new instance of Xoshiro256PlusPlus using the specified array of initial seed bytes. Instances of Xoshiro256PlusPlus created with the same seed array in the same program execution generate identical sequences of values.

Parameters
seed:byte[]

the initial seed

Method Detail

copyback to summary
public Xoshiro256PlusPlus copy()

Implements java.util.random.RandomGenerator.LeapableGenerator.copy.

Doc from java.util.random.RandomGenerator.LeapableGenerator.copy.

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).

Returns:Xoshiro256PlusPlus

a new object that is a copy of this generator

jumpback to summary
public void jump()

Implements java.util.random.RandomGenerator.JumpableGenerator.jump.

Doc from java.util.random.RandomGenerator.JumpableGenerator.jump.

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.

Annotations
@Override
jumpAlgorithmback to summary
private void jumpAlgorithm(long[] table)
jumpDistanceback to summary
public double jumpDistance()

Implements java.util.random.RandomGenerator.JumpableGenerator.jumpDistance.

Doc from java.util.random.RandomGenerator.JumpableGenerator.jumpDistance.

Returns the distance by which the jump() method will jump forward within the state cycle of this generator object.

Returns:double

the default jump distance (as a double value)

Annotations
@Override
leapback to summary
public void leap()

Implements java.util.random.RandomGenerator.LeapableGenerator.leap.

Doc from java.util.random.RandomGenerator.LeapableGenerator.leap.

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.

Annotations
@Override
leapDistanceback to summary
public double leapDistance()

Implements java.util.random.RandomGenerator.LeapableGenerator.leapDistance.

Doc from java.util.random.RandomGenerator.LeapableGenerator.leapDistance.

Returns the distance by which the leap() method will leap forward within the state cycle of this generator object.

Returns:double

the default leap distance (as a double value)

Annotations
@Override
nextLongback to summary
public long nextLong()

Implements java.util.random.RandomGenerator.nextLong.

Doc from java.util.random.RandomGenerator.nextLong.

Returns a pseudorandomly chosen long value.

Returns:long

a pseudorandomly chosen long value

Annotations
@Override