The default random number generator.
On JVM this generator is thread-safe, its methods can be invoked from multiple threads.
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
}
Gets the next random bitCount number of bits.
Gets the next random Boolean value.
Fills the specified byte array with random bytes and returns it.
Creates a byte array of the specified size, filled with random bytes.
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.
Gets the next random Float value uniformly distributed between 0 (inclusive) and 1 (exclusive).
Gets the next random non-negative Int
from the random number generator less than the specified until bound.
© 2010–2020 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/-random/-default/index.html