Created
January 7, 2023 06:24
-
-
Save geekyorion/c28b9c9687a661f7be6f67383e13d898 to your computer and use it in GitHub Desktop.
get random ID using simple methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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