Random.nextBoolean所在位置是kotlin.random.Random.nextBoolean,其相关用法介绍如下。

用法:

open fun nextBoolean(): Boolean
fun nextBoolean(): Boolean

获取下一个随机 Boolean 值。

例子:

import kotlin.math.sin
import kotlin.random.Random
import kotlin.test.assertTrue

fun main(args: Array<String>) {
//sampleStart
val presents = listOf("Candy", "Balloon", "Ball")
// a random partition, the result may be different every time
val (alicePresents, bobPresents) = presents.partition { Random.nextBoolean() }

println("Alice receives $alicePresents")
println("Bob receives $bobPresents")
//sampleEnd
}

输出:

Alice receives [Ball]
Bob receives [Candy, Balloon]