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

public Class RandomSupport

extends Object
Class Inheritance
Imports
java.util.Objects, .Spliterator, java.util.function.Consumer, .DoubleConsumer, .IntConsumer, .LongConsumer, java.util.random.RandomGenerator, .RandomGenerator.SplittableGenerator, java.util.stream.DoubleStream, .IntStream, .LongStream, .Stream, .StreamSupport

Low-level utility methods helpful for implementing pseudorandom number generators.

This class is mostly for library writers creating specific implementations of the interface RandomGenerator. As an internal package it is not intended for general use.

Since
17

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
RandomSupport.AbstractArbitrarilyJumpableGenerator

This class provides much of the implementation of the ArbitrarilyJumpableGenerator interface, to minimize the effort required to implement that interface.

public abstract static class
RandomSupport.AbstractSpliteratorGenerator

This class overrides the stream-producing methods (such as ints()) in class RandomGenerator to provide Spliterator-based implementations that support potentially parallel execution.

public abstract static class
RandomSupport.AbstractSplittableGenerator

This class provides much of the implementation of the SplittableGenerator interface, to minimize the effort required to implement this interface.

public abstract static class
RandomSupport.AbstractSplittableWithBrineGenerator

This class provides much of the implementation of the SplittableGenerator interface, to minimize the effort required to implement this interface.

pack-priv static class
RandomSupport.DoubleZigguratTables

Implementation support for modified-ziggurat implementation of nextExponential()

This Java class was generated automatically by a program `create_ziggurat_tables.c`.

public static class
RandomSupport.RandomDoublesSpliterator

Spliterator for double streams.

public static class
RandomSupport.RandomIntsSpliterator

Spliterators for int streams.

public static class
RandomSupport.RandomLongsSpliterator

Spliterator for long streams.

public abstract static class
RandomSupport.RandomSpliterator

Base class for making Spliterator classes for streams of randomly chosen values.

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final int
GOLDEN_RATIO_32

The first 32 bits of the golden ratio (1+sqrt(5))/2, forced to be odd.

public static final long
GOLDEN_RATIO_64

The first 64 bits of the golden ratio (1+sqrt(5))/2, forced to be odd.

private static final double
MAX_EXPONENTIAL

Largest value that computeNextExponential can ever return.

public static final int
SILVER_RATIO_32

The first 32 bits of the silver ratio 1+sqrt(2), forced to be odd.

public static final long
SILVER_RATIO_64

The first 64 bits of the silver ratio 1+sqrt(2), forced to be odd.

private static final boolean

Constructor Summary

AccessConstructor and Description
protected
RandomSupport()

Explicit constructor.

Method Summary

Modifier and TypeMethod and Description
public static double

Returns:

a pseudorandomly chosen double value, which will be between origin (inclusive) and bound exclusive unless origin is greater than or equal to bound, in which case it will be between 0.0 (inclusive) and 1.0 (exclusive)
boundedNextDouble
(RandomGenerator
a random number generator to be used as a source of pseudorandom double values
rng
,
double
the least value that can be produced, unless greater than or equal to bound; must be finite
origin
,
double
the upper bound (exclusive), unless origin is greater than or equal to bound; must be finite
bound
)

This is the form of nextDouble() used by a DoubleStream Spliterator and by the public method nextDouble(origin, bound).

public static double

Returns:

a pseudorandomly chosen double value between zero (inclusive) and bound (exclusive)
boundedNextDouble
(RandomGenerator
a random number generator to be used as a source of pseudorandom double values
rng
,
double
the upper bound (exclusive); must be finite and greater than zero
bound
)

This is the form of nextDouble() used by the public method nextDouble(bound).

public static float

Returns:

a pseudorandomly chosen float value, which will be between origin (inclusive) and bound exclusive unless origin is greater than or equal to bound, in which case it will be between 0.0 (inclusive) and 1.0 (exclusive)
boundedNextFloat
(RandomGenerator
a random number generator to be used as a source of pseudorandom float values
rng
,
float
the least value that can be produced, unless greater than or equal to bound; must be finite
origin
,
float
the upper bound (exclusive), unless origin is greater than or equal to bound; must be finite
bound
)

This is the form of nextFloat() used by a Stream<Float> Spliterator (if there were any) and by the public method nextFloat(origin, bound).

public static float

Returns:

a pseudorandomly chosen float value between zero (inclusive) and bound (exclusive)
boundedNextFloat
(RandomGenerator
a random number generator to be used as a source of pseudorandom float values
rng
,
float
the upper bound (exclusive); must be finite and greater than zero
bound
)

This is the form of nextFloat() used by the public method nextFloat(bound).

public static int

Returns:

a pseudorandomly chosen int value, which will be between origin (inclusive) and bound exclusive unless origin is greater than or equal to bound
boundedNextInt
(RandomGenerator
a random number generator to be used as a source of pseudorandom int values
rng
,
int
the least value that can be produced, unless greater than or equal to bound
origin
,
int
the upper bound (exclusive), unless origin is greater than or equal to bound
bound
)

This is the form of nextInt() used by an IntStream Spliterator and by the public method nextInt(origin, bound).

public static int

Returns:

a pseudorandomly chosen long value
boundedNextInt
(RandomGenerator
a random number generator to be used as a source of pseudorandom long values
rng
,
int
the upper bound (exclusive); must be greater than zero
bound
)

This is the form of nextInt() used by the public method nextInt(bound).

public static long

Returns:

a pseudorandomly chosen long value, which will be between origin (inclusive) and bound exclusive unless origin is greater than or equal to bound
boundedNextLong
(RandomGenerator
a random number generator to be used as a source of pseudorandom long values
rng
,
long
the least value that can be produced, unless greater than or equal to bound
origin
,
long
the upper bound (exclusive), unless origin is greater than or equal to bound
bound
)

This is the form of nextLong() used by a LongStream Spliterator and by the public method nextLong(origin, bound).

public static long

Returns:

a pseudorandomly chosen long value
boundedNextLong
(RandomGenerator
a random number generator to be used as a source of pseudorandom long values
rng
,
long
the upper bound (exclusive); must be greater than zero
bound
)

This is the form of nextLong() used by the public method nextLong(bound).

public static void
checkBound(float
the upper bound (exclusive)
bound
)

Checks a float upper bound value for validity.

public static void
checkBound(double
the upper bound (exclusive)
bound
)

Checks a double upper bound value for validity.

public static void
checkBound(int
the upper bound (exclusive)
bound
)

Checks an int upper bound value for validity.

public static void
checkBound(long
the upper bound (exclusive)
bound
)

Checks a long upper bound value for validity.

public static void
checkRange(float
the least value (inclusive) in the range
origin
,
float
the upper bound (exclusive) of the range
bound
)

Checks a float range for validity.

public static void
checkRange(double
the least value (inclusive) in the range
origin
,
double
the upper bound (exclusive) of the range
bound
)

Checks a double range for validity.

public static void
checkRange(int
the least value that can be returned
origin
,
int
the upper bound (exclusive) for the returned value
bound
)

Checks an int range for validity.

public static void
checkRange(long
the least value that can be returned
origin
,
long
the upper bound (exclusive) for the returned value
bound
)

Checks a long range for validity.

public static void
checkStreamSize(long
the proposed stream size
streamSize
)

Check a long proposed stream size for validity.

public static double

Returns:

a nonnegative double value chosen pseudorandomly from an exponential distribution whose mean is 1
computeNextExponential
(RandomGenerator
an instance of RandomGenerator, used to generate uniformly pseudorandomly chosen long values
rng
)

Implementation support for the nextExponential method of java.util.random.RandomGenerator.

public static double

Returns:

a nonnegative double value chosen pseudorandomly from an exponential distribution whose mean is 1
computeNextExponentialSoftCapped
(RandomGenerator
an instance of RandomGenerator, used to generate uniformly pseudorandomly chosen long values
rng
,
double maxValue)

Generates a pseudorandom value x such that Math.min(x, maxValue) follows the same distribution as it would if x was exponentially distributed with mean 1, but with a worst-case number of calls to RandomGenerator#nextLong() that's linear with maxValue.

public static double

Returns:

a nonnegative double value chosen pseudorandomly from a Gaussian (normal) distribution whose mean is 0 and whose standard deviation is 1.
computeNextGaussian
(RandomGenerator
an instance of RandomGenerator, used to generate uniformly pseudorandomly chosen long values
rng
)

Implementation support for the nextGaussian methods of java.util.random.RandomGenerator.

public static int[]

Returns:

an array of length n containing int seed values
convertSeedBytesToInts
(byte[]
an array of byte values
seed
,
int
the length of the result array (should be nonnegative)
n
,
int
the number of trailing result elements that are required to be not all zero (should be nonnegative but not larger than n)
z
)

Given an array of seed bytes of any length, construct an array of int seed values of length n, such that the last z values are not all zero.

public static long[]

Returns:

an array of length n containing long seed values
convertSeedBytesToLongs
(byte[]
an array of byte values
seed
,
int
the length of the result array (should be nonnegative)
n
,
int
the number of trailing result elements that are required to be not all zero (should be nonnegative but not larger than n)
z
)

Given an array of seed bytes of any length, construct an array of long seed values of length n, such that the last z values are not all zero.

public static long

Returns:

a long value, randomly chosen using appropriate environmental entropy
initialSeed
()

Returns a long value (chosen from some machine-dependent entropy source) that may be useful for initializing a source of seed values for instances of RandomGenerator created by zero-argument constructors.

public static int

Returns:

the result of hashing z
mixLea32
(int
any long value
z
)

Computes Doug Lea's 32-bit mixing function.

public static long

Returns:

the result of hashing z
mixLea64
(long
any long value
z
)

Computes Doug Lea's 64-bit mixing function.

public static int

Returns:

the result of hashing z
mixMurmur32
(int
any long value
z
)

Computes the 32-bit mixing function for MurmurHash3.

public static long

Returns:

the result of hashing z
mixMurmur64
(long
any long value
z
)

Computes the 64-bit mixing function for MurmurHash3.

public static long

Returns:

the result of hashing z
mixStafford13
(long
any long value
z
)

Computes Stafford variant 13 of the 64-bit mixing function for MurmurHash3.

private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait