Spec-Zone.ru › Kotlin 1.6

nextFloat

kotlin-stdlib / kotlin.random / Random / nextFloat
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
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
}

© 2010–2022 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.random/-random/next-float.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API