nextBits
Требования к платформе и версии: JVM (1.0), JS (1.0), Native (1.0)
fun nextBits(bitCount: Int): Int
Получает следующие случайные bitCount биты.
Генерирует Int, в котором нижние bitCount биты заполнены случайными значениями, а оставшиеся верхние биты — нулями.
import kotlin.math.sin
import kotlin.random.Random
import kotlin.test.assertTrue
fun main(args: Array<String>) {
//sampleStart
// always generates a 0
println(Random.nextBits(0))
// randomly generates a 0 or 1
println(Random.nextBits(1))
// generates a random non-negative Int value less than 256
println(Random.nextBits(8))
// generates a random Int value, may generate a negative value as well
println(Random.nextBits(32))
//sampleEnd
}Параметры
bitCount - количество генерируемых битов, должно быть в диапазоне от 0 до 32, в противном случае поведение не определено.
© 2010–2023 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/-default/next-bits.html