Random
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.
Since Kotlin
1.3Samples
import kotlin.math.sin
import kotlin.random.Random
import kotlin.test.assertTrue
fun main() {
//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
}
Constructors
Types
Functions
Gets the next random Boolean value.
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.
Gets the next random Int
from the random number generator in the specified range.
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.
Gets the next random Long
from the random number generator in the specified range.
Inheritors
Extensions
Creates a java.util.Random instance that uses the specified Kotlin Random generator as a randomness source.
Fills the specified unsigned byte array with random bytes and returns it.
Creates an unsigned byte array of the specified size, filled with random bytes.