Skip to content

Instantly share code, notes, and snippets.

@tokdaniel
Created September 5, 2019 13:46
Show Gist options
  • Save tokdaniel/85d658bb84df2a60d427bddf8fc4a9b4 to your computer and use it in GitHub Desktop.
Save tokdaniel/85d658bb84df2a60d427bddf8fc4a9b4 to your computer and use it in GitHub Desktop.
Relatively safe ID generator, fixed length option
const ID = () => (Date.now() + Math.random().toString(36)
.substr(2, 9))
.split('')
.sort(() => (0.5 > Math.random() ? -1 : 1))
.join('');
const createFixedLengthID = (length) => ID().padStart(length, ID())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment