Package kotlin.random

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

Types

Common
JVM
JS
Native
1.3

Random

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

abstract class Random

Extensions for External Classes

Functions

JVM
1.3

asJavaRandom

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

fun Random.asJavaRandom(): Random
Common
JVM
JS
Native
1.3

nextInt

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

fun Random.nextInt(range: IntRange): Int
Common
JVM
JS
Native
1.3

nextLong

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

fun Random.nextLong(range: LongRange): Long
Common
JVM
JS
Native
1.3

nextUBytes

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

fun Random.nextUBytes(array: UByteArray): UByteArray

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

fun Random.nextUBytes(size: Int): UByteArray

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

fun Random.nextUBytes(
    array: UByteArray,
    fromIndex: Int = 0,
    toIndex: Int = array.size
): UByteArray
Common
JVM
JS
Native
1.3

nextUInt

Gets the next random UInt from the random number generator.

fun Random.nextUInt(): UInt

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

fun Random.nextUInt(until: UInt): UInt

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

fun Random.nextUInt(from: UInt, until: UInt): UInt

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

fun Random.nextUInt(range: UIntRange): UInt
Common
JVM
JS
Native
1.3

nextULong

Gets the next random ULong from the random number generator.

fun Random.nextULong(): ULong

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

fun Random.nextULong(until: ULong): ULong

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

fun Random.nextULong(from: ULong, until: ULong): ULong

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

fun Random.nextULong(range: ULongRange): ULong
Common
JVM
JS
Native
1.3

Random

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

fun Random(seed: Int): Random

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

fun Random(seed: Long): Random