Package kotlin.random

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

Types

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

Random

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

abstract class Random

Extensions for External Classes

Platform and version requirements: JVM (1.3)

java.util.Random

Functions

Platform and version requirements: 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
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

nextInt

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

fun Random.nextInt(range: IntRange): Int
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

nextLong

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

fun Random.nextLong(range: LongRange): Long
Platform and version requirements: JVM (1.3), JS (1.3), 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
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

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
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

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
Platform and version requirements: JVM (1.3), JS (1.3), 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

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.random/index.html