Created
September 14, 2019 18:26
-
-
Save craigphicks/aa96696d303f20fb72f46f363c2f8b91 to your computer and use it in GitHub Desktop.
A non-crypto js function for creating random alphanum strings - no dependencies
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 makeNonCryptoRandomAlphaNumString(length) { | |
function tf(n) { | |
if (n < 26) return 65 + n | |
else if (n < 52) return 97 + n - 26 | |
else return 48 + n - 52 | |
} | |
var result = '' | |
for (var i = 0; i < length; i++) { | |
let idx = Math.floor(Math.random() * 62) | |
result += String.fromCharCode(tf(idx)) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment