Skip to content

Instantly share code, notes, and snippets.

@atotic
Created July 13, 2015 04:16
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 atotic/447efe26ef775a8e14f8 to your computer and use it in GitHub Desktop.
Save atotic/447efe26ef775a8e14f8 to your computer and use it in GitHub Desktop.
js randomString
exports.randomString = function (len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment