Added in API level 35

LeapableGenerator

interface LeapableGenerator : RandomGenerator.JumpableGenerator
java.util.random.RandomGenerator.LeapableGenerator

This interface is designed to provide a common protocol for objects that generate sequences of pseudorandom values and can easily not only jump but also leap forward, by a large amount (ex. 2128), to a very distant point in the state cycle. Typically one will construct a series of LeapableGenerator objects by iterative leaping from a single original LeapableGenerator object, and then for each such object produce a subseries of objects by iterative jumping. There is little conceptual difference between leaping and jumping, but typically a leap will be a very long jump in the state cycle (perhaps distance 2128 or so).

Ideally, all LeapableGenerator objects produced by iterative leaping and jumping from a single original LeapableGenerator object are statistically independent of one another and individually uniform. In practice, one must settle for some approximation to independence and uniformity. In particular, a specific implementation may assume that each generator in a stream produced by the leaps method is used to produce (by jumping) a number of objects no larger than 264. Implementors are advised to use algorithms whose period is at least 2191.

Methods are provided to perform a single leap operation and also to produce a stream of generators produced from the original by iterative copying and leaping of internal state. The generators produced must implement the JumpableGenerator interface but need not also implement the LeapableGenerator interface. A typical strategy for a multithreaded application is to create a single LeapableGenerator object, calls its leaps method exactly once, and then parcel out generators from the resulting stream, one to each thread. Then the jump() method of each such generator be called to produce a substream of generator objects.

Objects that implement LeapableGenerator are typically not cryptographically secure. Consider instead using SecureRandom to get a cryptographically secure pseudo-random number generator for use by security-sensitive applications.

Summary

Public methods
abstract RandomGenerator.LeapableGenerator!

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

open RandomGenerator.JumpableGenerator!

Copy this generator, leap this generator forward, then return the copy.

abstract Unit

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.

abstract Double

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

open Stream<RandomGenerator.JumpableGenerator!>!

Returns an effectively unlimited stream of new pseudorandom number generators, each of which implements the JumpableGenerator interface.

open Stream<RandomGenerator.JumpableGenerator!>!
leaps(streamSize: Long)

Returns a stream producing the given streamSize number of new pseudorandom number generators, each of which implements the JumpableGenerator interface.

open static RandomGenerator.LeapableGenerator!
of(name: String!)

Returns an instance of LeapableGenerator that utilizes the name algorithm.

Inherited functions

Public methods

copy

Added in API level 35
abstract fun copy(): RandomGenerator.LeapableGenerator!

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

Return
RandomGenerator.LeapableGenerator! a new object that is a copy of this generator

copyAndLeap

Added in API level 35
open fun copyAndLeap(): RandomGenerator.JumpableGenerator!

Copy this generator, leap this generator forward, then return the copy.

Return
RandomGenerator.JumpableGenerator! a copy of this generator object before the leap occurred

leap

Added in API level 35
abstract fun leap(): Unit

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

Added in API level 35
abstract fun leapDistance(): Double

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

Return
Double the default leap distance (as a double value)

leaps

Added in API level 35
open fun leaps(): Stream<RandomGenerator.JumpableGenerator!>!

Returns an effectively unlimited stream of new pseudorandom number generators, each of which implements the JumpableGenerator interface.

Return
Stream<RandomGenerator.JumpableGenerator!>! a stream of objects that implement the JumpableGenerator interface

leaps

Added in API level 35
open fun leaps(streamSize: Long): Stream<RandomGenerator.JumpableGenerator!>!

Returns a stream producing the given streamSize number of new pseudorandom number generators, each of which implements the JumpableGenerator interface.

Parameters
streamSize Long: the number of generators to generate
Return
Stream<RandomGenerator.JumpableGenerator!>! a stream of objects that implement the JumpableGenerator interface
Exceptions
java.lang.IllegalArgumentException if streamSize is less than zero

of

Added in API level 35
open static fun of(name: String!): RandomGenerator.LeapableGenerator!

Returns an instance of LeapableGenerator that utilizes the name algorithm.

Parameters
name String!: Name of random number generator algorithm
Return
RandomGenerator.LeapableGenerator! An instance of LeapableGenerator
Exceptions
java.lang.NullPointerException if name is null
java.lang.IllegalArgumentException if the named algorithm is not found