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.

Revisions

  1. geekyorion created this gist Jan 7, 2023.
    7 changes: 7 additions & 0 deletions randomID.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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