Created
July 30, 2018 13:37
-
-
Save liyuntao/4210ab19e9014f8baf121b20d8902576 to your computer and use it in GitHub Desktop.
get a random number in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ClosedRange<Int>.random() = | |
Random().nextInt((endInclusive + 1) - start) + start | |
// usage | |
(0..10).random() | |
(0 until 10).random() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment