Skip to content

Instantly share code, notes, and snippets.

@megadix
Created January 15, 2020 09:53
Show Gist options
  • Select an option

  • Save megadix/12969a57f47483ecede7fd47b9840a0c to your computer and use it in GitHub Desktop.

Select an option

Save megadix/12969a57f47483ecede7fd47b9840a0c to your computer and use it in GitHub Desktop.
Javascript random alphanumeric
function randomAlpha(n) {
let result = '';
for (let i = 0; i < n; i++) {
const rint = Math.floor(Math.random() * Math.floor(15)) + 10;
const c = rint.toString(26);
result += c;
}
return result;
}
console.log(randomAlpha(1));
console.log(randomAlpha(3));
console.log(randomAlpha(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment