randomOrNull

inline fun <T> Array<out T>.randomOrNull(): T?(source)

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

Since Kotlin

1.4

fun <T> Array<out T>.randomOrNull(random: Random): T?(source)

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

Since Kotlin

1.4

inline fun <T> Collection<T>.randomOrNull(): T?(source)

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

Since Kotlin

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.

Since Kotlin

1.4