📜  kotlin 代码示例中的随机类

📅  最后修改于: 2022-03-11 14:53:34.536000             🧑  作者: Mango

代码示例2
import kotlin.random.Random
 
fun rand(start: Int, end: Int): Int {
    require(start <= end) { "Illegal Argument" }
    val rand = Random(System.nanoTime())
    return (start..end).random(rand)
}
 
fun main() {
    val start = 5
    val end = 9
 
    for (i in 1..5) println(rand(start, end))
}