randomOrNull

Common
JVM
JS
Native
1.4
fun IntRange.randomOrNull(): Int?
(source)
fun LongRange.randomOrNull(): Long?
(source)
fun CharRange.randomOrNull(): Char?
(source)
fun UIntRange.randomOrNull(): UInt?
(source)
fun ULongRange.randomOrNull(): ULong?
(source)

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

Common
JVM
JS
Native
1.4
fun IntRange.randomOrNull(random: Random): Int?
(source)
fun LongRange.randomOrNull(random: Random): Long?
(source)
fun CharRange.randomOrNull(random: Random): Char?
(source)
fun UIntRange.randomOrNull(random: Random): UInt?
(source)
fun ULongRange.randomOrNull(random: Random): ULong?
(source)

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