Skip to content

Instantly share code, notes, and snippets.

@lvnam96
Last active October 17, 2018 00:45
Show Gist options
  • Save lvnam96/592fa2a61bfc7de728ea6785197dae13 to your computer and use it in GitHub Desktop.
Save lvnam96/592fa2a61bfc7de728ea6785197dae13 to your computer and use it in GitHub Desktop.
Generate random string/characters in JavaScript (from Stack Overflow)
//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