Random

abstract class Random(source)

A Guest pseudorandom source. Seeded generators and Default are reproducible on Compukters; their sequences are independent of Kotlin/JVM implementations. Not a cryptographic source. Each call executes ordinary metered Guest instructions.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Default : Random

The shared, program-local sequence starts from seed 0L; aliases and tasks share its state.

Functions

Link copied to clipboard
abstract fun nextBits(bitCount: Int): Int

Returns random low bits with upper bits zero; bitCount must be in 0..32.

Link copied to clipboard
open fun nextBoolean(): Boolean
Link copied to clipboard
open fun nextBytes(array: ByteArray): ByteArray
open fun nextBytes(size: Int): ByteArray

open fun nextBytes(array: ByteArray, fromIndex: Int, toIndex: Int): ByteArray

Fills exactly [fromIndex, toIndex); invalid ranges leave both array and generator unchanged.

Link copied to clipboard
open fun nextDouble(): Double

Uniform 53-bit fraction in [0, 1).

open fun nextDouble(until: Double): Double

open fun nextDouble(from: Double, until: Double): Double

Finite bounds with an exclusive upper endpoint, including adjacent representable values.

Link copied to clipboard
open fun nextFloat(): Float

Uniform 24-bit fraction in [0, 1).

Link copied to clipboard
open fun nextInt(): Int

open fun nextInt(until: Int): Int

Uniform value in [0, until).

open fun nextInt(from: Int, until: Int): Int

Uniform value in [from, until); invalid bounds do not consume random bits.

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

Uniform value in the inclusive range, including the full Int domain.

Link copied to clipboard
open fun nextLong(): Long
open fun nextLong(until: Long): Long
open fun nextLong(from: Long, until: Long): Long
Link copied to clipboard

Uniform value in the inclusive range, including the full Long domain.

Link copied to clipboard

fun Random.nextUBytes(array: UByteArray, fromIndex: Int, toIndex: Int): UByteArray

Fills exactly [fromIndex, toIndex); invalid ranges do not consume state or modify the array.

Link copied to clipboard

Unsigned full-width bits from this source.

fun Random.nextUInt(until: UInt): UInt

Uniform value in the inclusive range, including the full UInt domain.

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

Uniform value in [from, until), using rejection before modulo reduction.

Link copied to clipboard

Unsigned full-width bits from this source.


Uniform value in the inclusive range, including the full ULong domain.

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

Uniform value in [from, until), using rejection before modulo reduction.