randomOrNull

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

inline fun <T> Array<out T>.randomOrNull(): T?(source)
fun main() {
    val empty = arrayOf<String>()
    println(empty.randomOrNull()) // null

    val colors = arrayOf("red", "green", "blue")
    println(colors.randomOrNull()) // random color from the array
}

Source