Created
March 22, 2022 05:26
-
-
Save web2ls/7538fa14e917de159a9f5720fca38f27 to your computer and use it in GitHub Desktop.
Generate random string
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 = (len) => { | |
| const chars = 'abcdefhijkmnprstwxyz123456789ABCDEFGHJKMNPQRSTWXYZ'; | |
| const totalLength = chars.length; | |
| let randomStr = ''; | |
| for (let i = 0; i < len; i += 1) { | |
| randomStr += chars.charAt(Math.floor(Math.random() * totalLength)); | |
| } | |
| return randomStr; | |
| }; | |
| // 🎉 'k4RrA5' | |
| console.log(randomString(6)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment