Skip to content

Instantly share code, notes, and snippets.

@fida10
Created February 22, 2022 20:45
Show Gist options
  • Save fida10/60993556b2f2ec1e838a8cc12ed4cc74 to your computer and use it in GitHub Desktop.
Save fida10/60993556b2f2ec1e838a8cc12ed4cc74 to your computer and use it in GitHub Desktop.
js random number function
function generateRandomString(length) {
for(var i = 0; i < length; i++){
var letterToAppend = Math.ceil(Math.random() * 26); //will return a number between 1 - 26
if(Math.floor(Math.random() * 10) % 2 == 0){
letterToAppend += 96;
} else {
letterToAppend += 64;
}
randomString += (String.fromCharCode(letterToAppend));
}
return randomString;
}
console.log(generateRandomString(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment