Last active
October 17, 2018 00:45
-
-
Save lvnam96/592fa2a61bfc7de728ea6785197dae13 to your computer and use it in GitHub Desktop.
Generate random string/characters in JavaScript (from Stack Overflow)
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
//https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript | |
(length => { | |
let text = ''; | |
const POSSIBLE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', | |
POSSIBLE_SCOPE = POSSIBLE_CHARS.length; | |
for (let i = 0; i < length; i += 1) { | |
text += POSSIBLE_CHARS.charAt(Math.floor(Math.random() * POSSIBLE_SCOPE)); | |
} | |
return text; | |
})(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment