Most visited

Recently visited

Added in API level 24

SplittableRandom

public final class SplittableRandom
extends Object

java.lang.Object
   ↳ java.util.SplittableRandom


一个统一的伪随机值生成器,适用于(在其他上下文中)用于隔离的并行计算,这些计算可能会生成子任务。 SplittableRandom支持方法用于生产类型的伪随机数intlongdouble具有类似用途作为类Random但在以下方面不同:

SplittableRandom实例不具有密码安全性。 请考虑在安全敏感的应用程序中使用SecureRandom 此外,除非system property java.util.secureRandomSeed设置为true否则默认构建的实例不使用加密随机种子。

Summary

Public constructors

SplittableRandom(long seed)

使用指定的初始种子创建一个新的SplittableRandom实例。

SplittableRandom()

创建一个新的SplittableRandom实例,该实例可能会生成统计独立于当前程序中任何其他实例的值的序列值; 并且可能并且通常确实会因程序调用而异。

Public methods

DoubleStream doubles(long streamSize)

返回产生所述给定流streamSize数的伪随机的double从该发电机和/或从它一个分割值; 每个值在零(包括)和一个(独占)之间。

DoubleStream doubles()

返回来自此生成器的伪随机数double的有效无限数据流和/或从其中分离出一个; 每个值在零(包括)和一个(独占)之间。

DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)

返回来自此生成器的伪随机数double的有效无限流和/或从其中分离出的一个; 每个值符合给定的原点(包括)和绑定(独占)。

DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound)

返回产生所述给定流streamSize数的伪随机的double从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

IntStream ints(long streamSize)

返回产生所述给定流 streamSize数的伪随机的 int从该发电机和/或从它一个分割值。

IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound)

返回产生所述给定流streamSize数的伪随机的int从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

IntStream ints(int randomNumberOrigin, int randomNumberBound)

返回来自该生成器的伪随机数int的有效无限流和/或从其中分离出一个; 每个值符合给定的原点(包括)和绑定(独占)。

IntStream ints()

返回来自此生成器的伪随机值 int的有效无限流和/或从其中分离出的一个值。

LongStream longs()

返回来自此生成器的伪随机数 long的有效无限数据流和/或从其中分离出一个。

LongStream longs(long streamSize)

返回产生所述给定流 streamSize数的伪随机的 long从该发电机和/或从它一个分割值。

LongStream longs(long randomNumberOrigin, long randomNumberBound)

返回来自此生成器的伪随机数long的有效无限流和/或从其中分离出的一个; 每个值符合给定的原点(包括)和绑定(独占)。

LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound)

返回产生所述给定流streamSize数的伪随机的long从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

boolean nextBoolean()

返回伪随机值 boolean值。

double nextDouble()

返回零(含)和一(独占)之间的伪随机值 double

double nextDouble(double bound)

返回0.0(包含)与指定的边界(不包括)之间的伪随机数 double

double nextDouble(double origin, double bound)

返回指定原点(包含)和绑定(独占)之间的伪随机值 double

int nextInt()

返回伪随机值 int值。

int nextInt(int origin, int bound)

返回指定原点(包含)与指定的边界(不包括)之间的伪随机值 int

int nextInt(int bound)

返回0(包含)和指定的边界(独占)之间的伪随机值 int

long nextLong(long bound)

返回零(包括)与指定的边界(独占)之间的伪随机值 long

long nextLong()

返回伪随机值 long值。

long nextLong(long origin, long bound)

返回指定原点(包含)与指定的边界(不包括)之间的伪随机值 long

SplittableRandom split()

构造并返回一个新的SplittableRandom实例,该实例与此实例不共享可变状态。

Inherited methods

From class java.lang.Object

Public constructors

SplittableRandom

Added in API level 24
SplittableRandom (long seed)

使用指定的初始种子创建一个新的SplittableRandom实例。 在同一程序中使用相同种子创建的SplittableRandom实例会生成相同的值序列。

Parameters
seed long: the initial seed

SplittableRandom

Added in API level 24
SplittableRandom ()

创建一个新的SplittableRandom实例,该实例可能会生成统计独立于当前程序中任何其他实例的值的序列值; 并且可能并且通常确实会因程序调用而异。

Public methods

doubles

Added in API level 24
DoubleStream doubles (long streamSize)

返回产生所述给定流streamSize数的伪随机的double从该发电机和/或从它一个分割值; 每个值在零(包括)和一个(独占)之间。

Parameters
streamSize long: the number of values to generate
Returns
DoubleStream a stream of double values
Throws
IllegalArgumentException if streamSize is less than zero

doubles

Added in API level 24
DoubleStream doubles ()

返回来自此生成器的伪随机数double的有效无限流和/或从其中分离出的一个; 每个值在零(包括)和一个(独占)之间。

Implementation Note:
  • This method is implemented to be equivalent to doubles(Long.MAX_VALUE).
Returns
DoubleStream a stream of pseudorandom double values

doubles

Added in API level 24
DoubleStream doubles (double randomNumberOrigin, 
                double randomNumberBound)

返回来自该生成器的伪随机数double的有效无限流和/或从其中分离出的一个; 每个值符合给定的原点(包括)和绑定(独占)。

Implementation Note:
  • This method is implemented to be equivalent to doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound).
Parameters
randomNumberOrigin double: the origin (inclusive) of each random value
randomNumberBound double: the bound (exclusive) of each random value
Returns
DoubleStream a stream of pseudorandom double values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if randomNumberOrigin is greater than or equal to randomNumberBound

doubles

Added in API level 24
DoubleStream doubles (long streamSize, 
                double randomNumberOrigin, 
                double randomNumberBound)

返回产生所述给定流streamSize数的伪随机的double从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

Parameters
streamSize long: the number of values to generate
randomNumberOrigin double: the origin (inclusive) of each random value
randomNumberBound double: the bound (exclusive) of each random value
Returns
DoubleStream a stream of pseudorandom double values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if streamSize is less than zero
IllegalArgumentException if randomNumberOrigin is greater than or equal to randomNumberBound

ints

Added in API level 24
IntStream ints (long streamSize)

返回产生所述给定流 streamSize数的伪随机的 int从该发电机和/或从它一个分割值。

Parameters
streamSize long: the number of values to generate
Returns
IntStream a stream of pseudorandom int values
Throws
IllegalArgumentException if streamSize is less than zero

ints

Added in API level 24
IntStream ints (long streamSize, 
                int randomNumberOrigin, 
                int randomNumberBound)

返回产生所述给定流streamSize数的伪随机的int从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

Parameters
streamSize long: the number of values to generate
randomNumberOrigin int: the origin (inclusive) of each random value
randomNumberBound int: the bound (exclusive) of each random value
Returns
IntStream a stream of pseudorandom int values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if streamSize is less than zero, or randomNumberOrigin is greater than or equal to randomNumberBound

ints

Added in API level 24
IntStream ints (int randomNumberOrigin, 
                int randomNumberBound)

返回来自此生成器的伪随机数int的有效无限流和/或从其中分离出的一个; 每个值符合给定的原点(包括)和绑定(独占)。

Implementation Note:
  • This method is implemented to be equivalent to ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound).
Parameters
randomNumberOrigin int: the origin (inclusive) of each random value
randomNumberBound int: the bound (exclusive) of each random value
Returns
IntStream a stream of pseudorandom int values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if randomNumberOrigin is greater than or equal to randomNumberBound

ints

Added in API level 24
IntStream ints ()

返回来自此生成器的伪随机数 int的有效无限流和/或从其中分离出的一个。

Implementation Note:
  • This method is implemented to be equivalent to ints(Long.MAX_VALUE).
Returns
IntStream a stream of pseudorandom int values

longs

Added in API level 24
LongStream longs ()

返回伪随机的有效无限流 long值从该发电机和/或从它一个分割。

Implementation Note:
  • This method is implemented to be equivalent to longs(Long.MAX_VALUE).
Returns
LongStream a stream of pseudorandom long values

longs

Added in API level 24
LongStream longs (long streamSize)

返回产生所述给定流 streamSize数的伪随机的 long从该发电机和/或从它一个分割值。

Parameters
streamSize long: the number of values to generate
Returns
LongStream a stream of pseudorandom long values
Throws
IllegalArgumentException if streamSize is less than zero

longs

Added in API level 24
LongStream longs (long randomNumberOrigin, 
                long randomNumberBound)

返回来自此生成器的伪随机数long的有效无限流和/或从其中分离出的一个; 每个值符合给定的原点(包括)和绑定(独占)。

Implementation Note:
  • This method is implemented to be equivalent to longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound).
Parameters
randomNumberOrigin long: the origin (inclusive) of each random value
randomNumberBound long: the bound (exclusive) of each random value
Returns
LongStream a stream of pseudorandom long values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if randomNumberOrigin is greater than or equal to randomNumberBound

longs

Added in API level 24
LongStream longs (long streamSize, 
                long randomNumberOrigin, 
                long randomNumberBound)

返回产生所述给定流streamSize数的伪随机的long从该发电机和/或从它一个分割值; 每个值符合给定的原点(包括)和绑定(独占)。

Parameters
streamSize long: the number of values to generate
randomNumberOrigin long: the origin (inclusive) of each random value
randomNumberBound long: the bound (exclusive) of each random value
Returns
LongStream a stream of pseudorandom long values, each with the given origin (inclusive) and bound (exclusive)
Throws
IllegalArgumentException if streamSize is less than zero, or randomNumberOrigin is greater than or equal to randomNumberBound

nextBoolean

Added in API level 24
boolean nextBoolean ()

返回伪随机值 boolean值。

Returns
boolean a pseudorandom boolean value

nextDouble

Added in API level 24
double nextDouble ()

返回0(含)和1( double之间的伪随机值 double

Returns
double a pseudorandom double value between zero (inclusive) and one (exclusive)

nextDouble

Added in API level 24
double nextDouble (double bound)

返回0.0(包含)和指定的边界(不包括)之间的伪随机值 double

Parameters
bound double: the upper bound (exclusive). Must be positive.
Returns
double a pseudorandom double value between zero (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if bound is not positive

nextDouble

Added in API level 24
double nextDouble (double origin, 
                double bound)

返回指定原点(包含)和绑定(独占)之间的伪随机值 double

Parameters
origin double: the least value returned
bound double: the upper bound (exclusive)
Returns
double a pseudorandom double value between the origin (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if origin is greater than or equal to bound

nextInt

Added in API level 24
int nextInt ()

返回伪随机值 int值。

Returns
int a pseudorandom int value

nextInt

Added in API level 24
int nextInt (int origin, 
                int bound)

返回一个伪随机 int指定的原点(含)和指定约束(不含)之间的值。

Parameters
origin int: the least value returned
bound int: the upper bound (exclusive)
Returns
int a pseudorandom int value between the origin (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if origin is greater than or equal to bound

nextInt

Added in API level 24
int nextInt (int bound)

返回零(包括)和指定的边界(独占)之间的伪随机值 int

Parameters
bound int: the upper bound (exclusive). Must be positive.
Returns
int a pseudorandom int value between zero (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if bound is not positive

nextLong

Added in API level 24
long nextLong (long bound)

返回零(包括)与指定的边界(独占)之间的伪随机值 long

Parameters
bound long: the upper bound (exclusive). Must be positive.
Returns
long a pseudorandom long value between zero (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if bound is not positive

nextLong

Added in API level 24
long nextLong ()

返回伪随机值 long值。

Returns
long a pseudorandom long value

nextLong

Added in API level 24
long nextLong (long origin, 
                long bound)

返回指定原点(包含)与指定的边界(不包含)之间的伪随机值 long

Parameters
origin long: the least value returned
bound long: the upper bound (exclusive)
Returns
long a pseudorandom long value between the origin (inclusive) and the bound (exclusive)
Throws
IllegalArgumentException if origin is greater than or equal to bound

split

Added in API level 24
SplittableRandom split ()

构造并返回一个新的SplittableRandom实例,该实例与此实例不共享可变状态。 然而,以极高的概率,由两个对象共同生成的值集具有相同的统计属性,就好像使用单个SplittableRandom对象由单个线程生成相同数量的值一样。 可以使用split()方法将两个对象中的任一个或两个对象进一步分割,并且相同的预期统计特性适用于由这种递归分割构造的整个发生器组。

Returns
SplittableRandom the new SplittableRandom instance

Hooray!