Created
July 18, 2019 09:48
-
-
Save EmmanuelGuther/494298a2350693cb32c706b89602655e to your computer and use it in GitHub Desktop.
Kotlin function random string
This file contains hidden or 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
| /** USAGE -> ('a'..'z').randomString(6) */ | |
| fun ClosedRange<Char>.randomString(lenght: Int) = | |
| (1..lenght) | |
| .map { (Random().nextInt(endInclusive.toInt() - start.toInt()) + start.toInt()).toChar() } | |
| .joinToString("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment