Package kotlin.random

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

Random
Link copied to clipboard
abstract class Random

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

Since Kotlin

1.3

Functions

asJavaRandom
Link copied to clipboard
fun Random.asJavaRandom(): Random

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

Since Kotlin

1.3
asKotlinRandom
Link copied to clipboard
fun Random.asKotlinRandom(): Random

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

Since Kotlin

1.3
nextInt
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
nextLong
Link copied to clipboard
fun Random.nextLong(range: LongRange): Long

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

Since Kotlin

1.3
nextUBytes
Link copied to clipboard
fun Random.nextUBytes(size: Int): UByteArray

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

Since Kotlin

1.3
fun Random.nextUBytes(array: UByteArray): UByteArray

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 UBytearray starting from fromIndex inclusive and ending toIndex exclusive with random UBytes.

Since Kotlin

1.3
nextUInt
Link copied to clipboard
fun Random.nextUInt(): UInt

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
fun Random.nextUInt(range: UIntRange): UInt

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
nextULong
Link copied to clipboard
fun Random.nextULong(): ULong

Gets the next random ULong from the random number generator.

Since Kotlin

1.5
fun Random.nextULong(until: ULong): ULong

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

Since Kotlin

1.5
fun Random.nextULong(range: ULongRange): ULong

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
Random
Link copied to clipboard
fun Random(seed: Int): Random

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

Since Kotlin

1.3
fun Random(seed: Long): Random

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

Since Kotlin

1.3