Random Numbers
kotlin.random.Random gives ints, doubles and booleans. Use a seed for repeatable values.
Example
import kotlin.random.Random
val r = Random(42)
println(r.nextInt(1, 7) in 1..6)
println(r.nextDouble() < 1)
println(listOf("a", "b", "c").random(r) in listOf("a", "b", "c"))Exercise
Range of ints.
r.nextInt(1, )
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.