random

Common
JVM
JS
Native
1.3
fun <T> Array<out T>.random(): T
fun ByteArray.random(): Byte
fun ShortArray.random(): Short
fun IntArray.random(): Int
fun LongArray.random(): Long
fun FloatArray.random(): Float
fun DoubleArray.random(): Double
fun BooleanArray.random(): Boolean
fun CharArray.random(): Char
fun UIntArray.random(): UInt
fun ULongArray.random(): ULong
fun UByteArray.random(): UByte
fun UShortArray.random(): UShort

Returns a random element from this array.

Exceptions

NoSuchElementException - if this array is empty.

Common
JVM
JS
Native
1.3
fun <T> Array<out T>.random(random: Random): T
fun ByteArray.random(random: Random): Byte
fun ShortArray.random(random: Random): Short
fun IntArray.random(random: Random): Int
fun LongArray.random(random: Random): Long
fun FloatArray.random(random: Random): Float
fun DoubleArray.random(random: Random): Double
fun BooleanArray.random(random: Random): Boolean
fun CharArray.random(random: Random): Char
fun UIntArray.random(random: Random): UInt
fun ULongArray.random(random: Random): ULong
fun UByteArray.random(random: Random): UByte
fun UShortArray.random(random: Random): UShort

Returns a random element from this array using the specified source of randomness.

Exceptions

NoSuchElementException - if this array is empty.

Common
JVM
JS
Native
1.3
fun <T> Collection<T>.random(): T

Returns a random element from this collection.

Exceptions

NoSuchElementException - if this collection is empty.

Common
JVM
JS
Native
1.3
fun <T> Collection<T>.random(random: Random): T

Returns a random element from this collection using the specified source of randomness.

Exceptions

NoSuchElementException - if this collection is empty.