Created
October 14, 2019 07:39
-
-
Save ducdhm/9f8552749b0ea52d41d056ba32ab2179 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const randomString = (length) => { | |
const letters = 'abcdefghijklmnopqrstuvwxyz'; | |
const numbers = '1234567890'; | |
const charset = `${letters}${letters.toUpperCase()}${numbers}`; | |
const randomCharacter = (character) => character[Math.floor(Math.random() * character.length)]; | |
let result = ''; | |
for (let i = 0; i < length; i++) { | |
result += randomCharacter(charset); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment