Skip to content

Instantly share code, notes, and snippets.

@sean-clayton
Last active February 2, 2019 02:11
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 sean-clayton/d59f30441d967bead84a3efc21ff0b98 to your computer and use it in GitHub Desktop.
Save sean-clayton/d59f30441d967bead84a3efc21ff0b98 to your computer and use it in GitHub Desktop.
Create a random n-digit string in JS.
function randomDigitString(n) {
var x = n;
if (typeof n !== "number") x = 1;
if (n < 1) x = 1;
if (n > 19) x = 19;
return Math.random().toString().substr(2, x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment