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.3
Samples
import samples.*
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)
assertTrue(randomValues != nextValues)
//sampleEnd
}
Constructors
Types
Functions
next Boolean
Link copied to clipboard
Gets the next random Boolean value.
next Double
Link copied to clipboard
Inheritors
Default
Link copied to clipboard
Extensions
as Java Random
Link copied to clipboard
Creates a java.util.Random instance that uses the specified Kotlin Random generator as a randomness source.
next UBytes
Link copied to clipboard
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.
fun Random.nextUBytes(array: UByteArray, fromIndex: Int = 0, toIndex: Int = array.size): UByteArray
Content copied to clipboard