next
Thanks for your feedback!
Was this page helpful?
Gets the next random bitCount number of bits.
Generates an Int
whose lower bitCount bits are filled with random values and the remaining upper bits are zero.
number of bits to generate, must be in range 0..32, otherwise the behavior is unspecified.
import kotlin.math.sin import kotlin.random.Random import kotlin.test.assertTrue fun main() { //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 }
xxxxxxxxxx
// 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))
Thanks for your feedback!