W3cubDocs

/Kotlin

randomOrNull

Platform and version requirements: JVM (1.4), JS (1.4), 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.

Platform and version requirements: JVM (1.4), JS (1.4), 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.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/random-or-null.html