Skip to content

Instantly share code, notes, and snippets.

@liyuntao
Created July 30, 2018 13:37
Show Gist options
  • Save liyuntao/4210ab19e9014f8baf121b20d8902576 to your computer and use it in GitHub Desktop.
Save liyuntao/4210ab19e9014f8baf121b20d8902576 to your computer and use it in GitHub Desktop.
get a random number in Kotlin
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