Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
An abstract class that is implemented by random number generator algorithms.
The companion object Random.Default is the default instance of Random.
To get a seeded instance of random generator use Random function.
import kotlin.random.Random
import kotlin.test.assertTrue
fun main(args: Array<String>) {
//sampleStart
val randomValues = List(10) { Random.nextInt(0, 100) }
// prints new sequence every time
println(randomValues)
val nextValues = List(10) { Random.nextInt(0, 100) }
println(nextValues)
println("randomValues != nextValues is ${randomValues != nextValues}") // true
//sampleEnd
}
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random bitCount number of bits.
abstract fun nextBits(bitCount: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Boolean value.
open fun nextBoolean(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Fills a subrange of the specified byte array starting from fromIndex inclusive and ending toIndex exclusive with random bytes.
open fun nextBytes(
array: ByteArray,
fromIndex: Int = 0,
toIndex: Int = array.size
): ByteArray
Fills the specified byte array with random bytes and returns it.
open fun nextBytes(array: ByteArray): ByteArray
Creates a byte array of the specified size, filled with random bytes.
open fun nextBytes(size: Int): ByteArray
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Double value uniformly distributed between 0 (inclusive) and 1 (exclusive).
open fun nextDouble(): Double
Gets the next random non-negative Double
from the random number generator less than the specified until bound.
open fun nextDouble(until: Double): Double
Gets the next random Double
from the random number generator in the specified range.
open fun nextDouble(from: Double, until: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Float value uniformly distributed between 0 (inclusive) and 1 (exclusive).
open fun nextFloat(): Float
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Int
from the random number generator.
Gets the next random non-negative Int
from the random number generator less than the specified until bound.
open fun nextInt(until: Int): Int
Gets the next random Int
from the random number generator in the specified range.
open fun nextInt(from: Int, until: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Long
from the random number generator.
open fun nextLong(): Long
Gets the next random non-negative Long
from the random number generator less than the specified until bound.
open fun nextLong(until: Long): Long
Gets the next random Long
from the random number generator in the specified range.
open fun nextLong(from: Long, until: Long): Long
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random bitCount number of bits.
fun nextBits(bitCount: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Boolean value.
fun nextBoolean(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Fills the specified byte array with random bytes and returns it.
fun nextBytes(array: ByteArray): ByteArray
Creates a byte array of the specified size, filled with random bytes.
fun nextBytes(size: Int): ByteArray
Fills a subrange of the specified byte array starting from fromIndex inclusive and ending toIndex exclusive with random bytes.
fun nextBytes(
array: ByteArray,
fromIndex: Int,
toIndex: Int
): ByteArray
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Double value uniformly distributed between 0 (inclusive) and 1 (exclusive).
Gets the next random non-negative Double
from the random number generator less than the specified until bound.
fun nextDouble(until: Double): Double
Gets the next random Double
from the random number generator in the specified range.
fun nextDouble(from: Double, until: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Float value uniformly distributed between 0 (inclusive) and 1 (exclusive).
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Int
from the random number generator.
Gets the next random non-negative Int
from the random number generator less than the specified until bound.
fun nextInt(until: Int): Int
Gets the next random Int
from the random number generator in the specified range.
fun nextInt(from: Int, until: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Gets the next random Long
from the random number generator.
Gets the next random non-negative Long
from the random number generator less than the specified until bound.
fun nextLong(until: Long): Long
Gets the next random Long
from the random number generator in the specified range.
fun nextLong(from: Long, until: Long): Long
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