Package-level declarations

Provides the default generator of pseudo-random values, the repeatable generator, and a base class for other RNG implementations.

Provides the default generator of pseudo-random values, the repeatable generator, and a base class for other RNG implementations.

Types

Link copied to clipboard
abstract class Random

An abstract class that is implemented by random number generator algorithms.

Since Kotlin 1.3

Functions

Link copied to clipboard

Creates a java.util.Random instance that uses the specified Kotlin Random generator as a randomness source.

Since Kotlin 1.3
Link copied to clipboard

Creates a Kotlin Random instance that uses the specified java.util.Random generator as a randomness source.

Since Kotlin 1.3
Link copied to clipboard
fun Random.nextInt(range: IntRange): Int

Gets the next random Int from the random number generator in the specified range.

Since Kotlin 1.3
Link copied to clipboard

Gets the next random Long from the random number generator in the specified range.

Since Kotlin 1.3
Link copied to clipboard

Creates an unsigned byte array of the specified size, filled with random bytes.

Since Kotlin 1.3

Fills the specified unsigned byte array with random bytes and returns it.

Since Kotlin 1.3
fun Random.nextUBytes(array: UByteArray, fromIndex: Int = 0, toIndex: Int = array.size): UByteArray

Fills a subrange of the specified UByte array starting from fromIndex inclusive and ending toIndex exclusive with random UBytes.

Since Kotlin 1.3
Link copied to clipboard

Gets the next random UInt from the random number generator.

Since Kotlin 1.5
fun Random.nextUInt(until: UInt): UInt

Gets the next random UInt from the random number generator less than the specified until bound.

Since Kotlin 1.5

Gets the next random UInt from the random number generator in the specified range.

Since Kotlin 1.5
fun Random.nextUInt(from: UInt, until: UInt): UInt

Gets the next random UInt from the random number generator in the specified range.

Since Kotlin 1.5
Link copied to clipboard

Gets the next random ULong from the random number generator.

Since Kotlin 1.5

Gets the next random ULong from the random number generator less than the specified until bound.

Since Kotlin 1.5

Gets the next random ULong from the random number generator in the specified range.

Since Kotlin 1.5
fun Random.nextULong(from: ULong, until: ULong): ULong

Gets the next random ULong from the random number generator in the specified range.

Since Kotlin 1.5
Link copied to clipboard
fun Random(seed: Int): Random

Returns a repeatable random number generator seeded with the given seed Int value.

Since Kotlin 1.3
fun Random(seed: Long): Random

Returns a repeatable random number generator seeded with the given seed Long value.

Since Kotlin 1.3