Skip to content

Instantly share code, notes, and snippets.

@gabeno
Last active January 2, 2016 22:39
Show Gist options
  • Save gabeno/8371169 to your computer and use it in GitHub Desktop.
Save gabeno/8371169 to your computer and use it in GitHub Desktop.
Random String of n 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