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)
An abstract class that is implemented by random number generator algorithms.
Extensions for External Classes
Platform and version requirements: JVM (1.3)
Functions
Platform and version requirements: JVM (1.3)
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)
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)
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)
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.3), JS (1.3), Native (1.3)
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.3), JS (1.3), Native (1.3)
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)
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