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

}
GitHub에서 이 글의 마크다운 원본 보기 & 수정 제안src/content/posts/2021-02-21-kotlin07_random

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

글 주소가 클립보드에 복사되었습니다.