Created
September 9, 2020 17:45
-
-
Save fny/07d2d6e2456dab7e4a1bf9667c283e14 to your computer and use it in GitHub Desktop.
Generate Random Base64 String
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
package greenlight.etc | |
import java.security.SecureRandom | |
import kotlin.math.abs | |
val BASE58_ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
fun randomBase58(length: Int): String { | |
return SecureRandom().ints(length.toLong()).toArray().map { | |
i -> BASE58_ALPHABET[abs(i) % 58] | |
}.joinToString("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment