W3cubDocs

/Kotlin

random

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> Array<out T>.random(): T
fun ByteArray.random(): Byte
fun ShortArray.random(): Short
fun IntArray.random(): Int
fun LongArray.random(): Long
fun FloatArray.random(): Float
fun DoubleArray.random(): Double
fun BooleanArray.random(): Boolean
fun CharArray.random(): Char
@ExperimentalUnsignedTypes fun UIntArray.random(): UInt
@ExperimentalUnsignedTypes fun ULongArray.random(): ULong
@ExperimentalUnsignedTypes fun UByteArray.random(): UByte
@ExperimentalUnsignedTypes fun UShortArray.random(): UShort

Returns a random element from this array.

Exceptions

NoSuchElementException - if this array is empty.

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> Array<out T>.random(random: Random): T
fun ByteArray.random(random: Random): Byte
fun ShortArray.random(random: Random): Short
fun IntArray.random(random: Random): Int
fun LongArray.random(random: Random): Long
fun FloatArray.random(random: Random): Float
fun DoubleArray.random(random: Random): Double
fun BooleanArray.random(random: Random): Boolean
fun CharArray.random(random: Random): Char
@ExperimentalUnsignedTypes fun UIntArray.random(
    random: Random
): UInt
@ExperimentalUnsignedTypes fun ULongArray.random(
    random: Random
): ULong
@ExperimentalUnsignedTypes fun UByteArray.random(
    random: Random
): UByte
@ExperimentalUnsignedTypes fun UShortArray.random(
    random: Random
): UShort

Returns a random element from this array using the specified source of randomness.

Exceptions

NoSuchElementException - if this array is empty.

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> Collection<T>.random(): T

Returns a random element from this collection.

Exceptions

NoSuchElementException - if this collection is empty.

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
fun <T> Collection<T>.random(random: Random): T

Returns a random element from this collection using the specified source of randomness.

Exceptions

NoSuchElementException - if this collection is empty.

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/random.html