Skip to content

Instantly share code, notes, and snippets.

@geekyorion
Created January 7, 2023 06:24
Show Gist options
  • Save geekyorion/c28b9c9687a661f7be6f67383e13d898 to your computer and use it in GitHub Desktop.
Save geekyorion/c28b9c9687a661f7be6f67383e13d898 to your computer and use it in GitHub Desktop.
get random ID using simple methods
const getRandomHex = () => Math.random().toString(16).substring(2);
const getTimeHex = () => Date.now().toString(16);
const getUniqueID = () => `${getRandomHex()}-${getTimeHex()}`;
console.log(getUniqueID()); // c3767dde3c52b-1858ae49650
console.log(getUniqueID()); // afea12d2bf3ee-1858ae49b2e
console.log(getUniqueID()); // c935374b52dc4-1858ae49e6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment