randomOrNull

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

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?
fun LongRange.randomOrNull(random: Random): Long?
fun CharRange.randomOrNull(random: Random): Char?
@ExperimentalUnsignedTypes fun UIntRange.randomOrNull(
    random: Random
): UInt?
@ExperimentalUnsignedTypes fun ULongRange.randomOrNull(
    random: Random
): ULong?

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