Skip to content

Instantly share code, notes, and snippets.

@fny
Created September 9, 2020 17:45
Show Gist options
  • Save fny/07d2d6e2456dab7e4a1bf9667c283e14 to your computer and use it in GitHub Desktop.
Save fny/07d2d6e2456dab7e4a1bf9667c283e14 to your computer and use it in GitHub Desktop.
Generate Random Base64 String
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