Created
June 11, 2017 18:57
-
-
Save Audhil/3e4332e14f0583062ead8147ab185d7b to your computer and use it in GitHub Desktop.
Tip to generate random password 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 generateRandomPassword(): String { | |
val chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
var passWord = "" | |
for (i in 0..31) { | |
passWord += chars[Math.floor(Math.random() * chars.length).toInt()] | |
} | |
return passWord | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Could be this way for a length of 8 password with visible ascii characters
var password = List(8){(0x21..0x7e).random().toChar()}.joinToString("")