Created
July 29, 2019 12:58
-
-
Save ar-android/c114a4832e268dd6b5c3bddc0ce4c44a to your computer and use it in GitHub Desktop.
Create random string in javascript.
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 randomString(length) { | |
var result = ''; | |
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
var charactersLength = characters.length; | |
for ( var i = 0; i < length; i++ ) { | |
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
} | |
return result; | |
} | |
console.log(randomString(5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment