randomOrNull

inline fun <K, V> Map<K, V>.randomOrNull(): Pair<K, V>?

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

Example:

mapOf(1 to 1, 2 to 2, 3 to 3, 4 to 4, 5 to 5).randomOrNull() // a pair from this map
mapOf().randomOrNull() // null

Since

1.1.0