randomOrNull

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

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?
fun ByteArray.randomOrNull(random: Random): Byte?
fun ShortArray.randomOrNull(random: Random): Short?
fun IntArray.randomOrNull(random: Random): Int?
fun LongArray.randomOrNull(random: Random): Long?
fun FloatArray.randomOrNull(random: Random): Float?
fun DoubleArray.randomOrNull(random: Random): Double?
fun BooleanArray.randomOrNull(random: Random): Boolean?
fun CharArray.randomOrNull(random: Random): Char?
@ExperimentalUnsignedTypes fun UIntArray.randomOrNull(
    random: Random
): UInt?
@ExperimentalUnsignedTypes fun ULongArray.randomOrNull(
    random: Random
): ULong?
@ExperimentalUnsignedTypes fun UByteArray.randomOrNull(
    random: Random
): UByte?
@ExperimentalUnsignedTypes fun UShortArray.randomOrNull(
    random: Random
): UShort?

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?

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?

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