Skip to content

Instantly share code, notes, and snippets.

@matthlavacka
Created March 11, 2019 23:44
Show Gist options
  • Save matthlavacka/cf710121a286e92d9cec2d6a85994c80 to your computer and use it in GitHub Desktop.
Save matthlavacka/cf710121a286e92d9cec2d6a85994c80 to your computer and use it in GitHub Desktop.
Random ID in JavaScript
function uniqueId() {
// Math.random should be unique because of its seeding algorithm.
// Convert it to base 36 (numbers + letters), and grab the first 9 characters
// after the decimal.
return Math.random()
.toString(36)
.substr(2, 9);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment