Created
February 22, 2022 20:45
-
-
Save fida10/60993556b2f2ec1e838a8cc12ed4cc74 to your computer and use it in GitHub Desktop.
js random number function
This file contains 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 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