Skip to content

Instantly share code, notes, and snippets.

@twiceyuan
Created May 17, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twiceyuan/b80822f3505109352b1355b8add578a3 to your computer and use it in GitHub Desktop.
Save twiceyuan/b80822f3505109352b1355b8add578a3 to your computer and use it in GitHub Desktop.
[nonce generator] 随机字符串生成器 #Kotlin
fun generateNonce(size: Int): String {
val nonceScope = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
val scopeSize = nonceScope.length
val nonceItem: (Int) -> Char = { nonceScope[(scopeSize * Math.random()).toInt()] }
return Array(size, nonceItem).joinToString("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment