random

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

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
(source)
fun ByteArray.random(random: Random): Byte
(source)
fun ShortArray.random(random: Random): Short
(source)
fun IntArray.random(random: Random): Int
(source)
fun LongArray.random(random: Random): Long
(source)
fun FloatArray.random(random: Random): Float
(source)
fun DoubleArray.random(random: Random): Double
(source)
fun BooleanArray.random(random: Random): Boolean
(source)
fun CharArray.random(random: Random): Char
(source)
@ExperimentalUnsignedTypes fun UIntArray.random(
    random: Random
): UInt

(source)
@ExperimentalUnsignedTypes fun ULongArray.random(
    random: Random
): ULong

(source)
@ExperimentalUnsignedTypes fun UByteArray.random(
    random: Random
): UByte

(source)
@ExperimentalUnsignedTypes fun UShortArray.random(
    random: Random
): UShort

(source)

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
(source)

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
(source)

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

Exceptions

NoSuchElementException - if this collection is empty.