Skip to content

Instantly share code, notes, and snippets.

@madcampos
Last active April 23, 2017 10:57
Show Gist options
  • Select an option

  • Save madcampos/b21c975b7e57fb2128cf2f1af33746c4 to your computer and use it in GitHub Desktop.

Select an option

Save madcampos/b21c975b7e57fb2128cf2f1af33746c4 to your computer and use it in GitHub Desktop.
Random string
//Generates a alphanumeric random string given the length.
//Tweet version: let randomString=(l)=>`${l?(Math.random()*Math.pow(10,18)).toString(36):''}${l>10?randomString(l-10):''}`.substr(0,l);
function randomString(length){
let str = '';
if (length) {
str += (Math.random() * Math.pow(10, 18)).toString(36);
}
if (length > 10) {
str = randomString(length - 10);
}
return str.substr(0, length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment