Created
October 4, 2019 10:23
-
-
Save noudadrichem/900831fd5c314cc4674858303397b5aa to your computer and use it in GitHub Desktop.
Return a random string with custom length from assigned characters
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
| function getRandomString(wishedIdLength) { | |
| var result = ''; | |
| var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=-[]\|'; | |
| var charactersLength = characters.length; | |
| for (let i = 0; i < wishedIdLength; i++ ) { | |
| result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
| } | |
| return result; | |
| } | |
| console.log(getRandomString(8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment