Dan Munro - Dev-Sec-Ops Engineer   News  Archives  Recommendations

Generating Random Numbers With Kotlin

Official Kotlin random API documentation: HERE

Generate a random number between 0 and 1:

fun randomDouble(): Double {
    return Math.random()
}

Generate a random number within a range:

fun randomWithinRange(start: Int, stop: Int): Int {
    return (start..stop).random()
}

Other resources

Written on May 29, 2020.