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

用法:

open fun nextFloat(): Float
fun nextFloat(): Float

获取下一个随机 Float 值,均匀分布在 0(包括)和 1(不包括)之间。

例子:

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

fun main(args: Array<String>) {
//sampleStart
if (Random.nextFloat() <= 0.3) {
    println("There was 30% possibility of rainy weather today and it is raining.")
} else {
    println("There was 70% possibility of sunny weather today and the sun is shining.")
}
//sampleEnd
}

输出:

There was 70% possibility of sunny weather today and the sun is shining.