Last active
August 6, 2018 21:02
-
-
Save leodutra/b7f386510d69d912479026d088105ba4 to your computer and use it in GitHub Desktop.
Function for random base 58 string generation (good for password redefinitions)
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
function randomBase58(digits) { | |
digits = digits || 0 | |
var base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.split('') | |
var result = '' | |
var char | |
while (result.length < digits) { | |
char = base58[Math.random() * 57 >> 0] | |
if (result.indexOf(char) === -1) result += char // avoid repetitions | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated a bit as IPFS will break if the pattern
Qm
exists in the result.