randomOrNull

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

Returns a random element from this array, or null if this array is empty.

Common
JVM
JS
Native
1.4
fun <T> Array<out T>.randomOrNull(random: Random): T?
(source)
fun ByteArray.randomOrNull(random: Random): Byte?
(source)
fun ShortArray.randomOrNull(random: Random): Short?
(source)
fun IntArray.randomOrNull(random: Random): Int?
(source)
fun LongArray.randomOrNull(random: Random): Long?
(source)
fun FloatArray.randomOrNull(random: Random): Float?
(source)
fun DoubleArray.randomOrNull(random: Random): Double?
(source)
fun BooleanArray.randomOrNull(random: Random): Boolean?
(source)
fun CharArray.randomOrNull(random: Random): Char?
(source)
@ExperimentalUnsignedTypes fun UIntArray.randomOrNull(
    random: Random
): UInt?

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

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

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

(source)

Returns a random element from this array using the specified source of randomness, or null if this array is empty.

Common
JVM
JS
Native
1.4
fun <T> Collection<T>.randomOrNull(): T?
(source)

Returns a random element from this collection, or null if this collection is empty.

Common
JVM
JS
Native
1.4
fun <T> Collection<T>.randomOrNull(random: Random): T?
(source)

Returns a random element from this collection using the specified source of randomness, or null if this collection is empty.