Skip to content

Instantly share code, notes, and snippets.

@ar-android
Created July 29, 2019 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ar-android/c114a4832e268dd6b5c3bddc0ce4c44a to your computer and use it in GitHub Desktop.
Save ar-android/c114a4832e268dd6b5c3bddc0ce4c44a to your computer and use it in GitHub Desktop.
Create random string in javascript.
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