APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.random

public final Class Xoroshiro128PlusPlus

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
Imports
java.util.concurrent.atomic.AtomicLong, java.util.random.RandomGenerator, .RandomGenerator.LeapableGenerator, jdk.internal.util.random.RandomSupport

A "jumpable and leapable" pseudorandom number generator (PRNG) whose period is roughly 2128. Class Xoroshiro128PlusPlus implements interfaces RandomGenerator and LeapableGenerator, and therefore supports methods for producing pseudorandomly chosen numbers of type int, long, float, and double as well as creating new Xoroshiro128PlusPlus objects by "jumping" or "leaping".

The class Xoroshiro128PlusPlus uses the xoroshiro128 algorithm (parameters 49, 21, 28) with the "++" scrambler that computes Long.rotateLeft(s0 + s1, 17) + s0. (See David Blackman and Sebastiano Vigna, "Scrambled Linear Pseudorandom Number Generators," ACM Transactions on Mathematical Software, 2021.) Its state consists of two long fields x0 and x1, which can take on any values provided that they are not both zero. The period of this generator is 2128-1.

The 64-bit values produced by the nextLong() method are equidistributed. To be precise, over the course of the cycle of length 2128-1, each nonzero long value is generated 264 times, but the value 0 is generated only 264-1 times. The values produced by the nextInt(), nextFloat(), and nextDouble() methods are likewise equidistributed.

Instances Xoroshiro128PlusPlus 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 Xoroshiro128PlusPlus that traverse other parts of the state cycle.

Instances of Xoroshiro128PlusPlus 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
defaultGen

The seed generator for default constructors.

private static final String
GROUP

Group name.

private static final long[]
private static final long[]
private long
x0

The per-instance state.

private long
x1

The per-instance state.

Constructor Summary

AccessConstructor and Description
public
Xoroshiro128PlusPlus(long
first word of the initial state
x0
,
long
second word of the initial state
x1
)

Basic constructor that initializes all fields from parameters.

public
Xoroshiro128PlusPlus(long
the initial seed
seed
)

Creates a new instance of Xoroshiro128PlusPlus using the specified long value as the initial seed.

public
Xoroshiro128PlusPlus()

Creates a new instance of Xoroshiro128PlusPlus 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
Xoroshiro128PlusPlus(byte[]
the initial seed
seed
)

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

Method Summary

Modifier and TypeMethod and Description
public Xoroshiro128PlusPlus
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

defaultGenback to summary
private static final AtomicLong defaultGen

The seed generator for default constructors.

GROUPback to summary
private static final String GROUP

Group name.

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 two fields x0 and x1 must be nonzero.

x1back to summary
private long x1

The per-instance state. At least one of the two fields x0 and x1 must be nonzero.

Constructor Detail

Xoroshiro128PlusPlusback to summary
public Xoroshiro128PlusPlus(long x0, long x1)

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

Xoroshiro128PlusPlusback to summary
public Xoroshiro128PlusPlus(long seed)

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

Parameters
seed:long

the initial seed

Xoroshiro128PlusPlusback to summary
public Xoroshiro128PlusPlus()

Creates a new instance of Xoroshiro128PlusPlus 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.

Xoroshiro128PlusPlusback to summary
public Xoroshiro128PlusPlus(byte[] seed)

Creates a new instance of Xoroshiro128PlusPlus using the specified array of initial seed bytes. Instances of Xoroshiro128PlusPlus 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 Xoroshiro128PlusPlus 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).

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.

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.

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.

Annotations
@Override