Last active
January 2, 2016 22:39
-
-
Save gabeno/8371169 to your computer and use it in GitHub Desktop.
Random String of n characters
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 randomString(n) { | |
var str = ""; | |
for (var i=0; i<n; i++) { | |
str += String.fromCharCode(Math.floor(Math.random()*26 + 97)) | |
} | |
return str; | |
} | |
randomString(5) // => "xkcdy" | |
randomString(7) // => "idhmtus" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment