Spec-Zone.ru › Kotlin 2

nextBoolean

kotlin-stdlib/kotlin.random/Random/nextBoolean

Версия Kotlin: 1.3

open fun nextBoolean(): Boolean

Возвращает следующее случайное значение типа Boolean.

Примеры

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

fun main() { 
   //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
}

© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.random/-random/next-boolean.html

Spec-Zone.ru

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