f_
frhyme.code
•java•⏱ 약 1분 소요

Kotlin - Random

  • kotlin.random.Random을 통해 random을 사용할 수 있습니다.
import kotlin.random.Random;

fun main() {
    println(Random.nextDouble())
    // 0.8495425362538855

    println(Random.nextInt(0, 5))
    // 2
    
    // Random with Seed
    var randomGeneratorSeed0 = Random(0)
    println(randomGeneratorSeed0.nextInt())
    // -1934310868

    randomGeneratorSeed0 = Random(0)
    println(randomGeneratorSeed0.nextInt())
    // -1934310868

}

💡RELATED ARTICLES · 함께 읽으면 좋은 연관 포스트