Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created July 18, 2019 09:48
Show Gist options
  • Select an option

  • Save EmmanuelGuther/494298a2350693cb32c706b89602655e to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelGuther/494298a2350693cb32c706b89602655e to your computer and use it in GitHub Desktop.
Kotlin function random string
/** 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