Last active
February 2, 2021 18:22
-
-
Save swimauger/50d2776804c27d0084340d5d3ae85a44 to your computer and use it in GitHub Desktop.
UUID Generator v2 : Using Generators, yield, and 999,999,999,999 100% unique ids
This file contains 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
function* UUIDGenerator() { | |
for (let i = 100000000000; true; i++) { | |
yield `${`${i}`.substr(0, 4)}-${`${i}`.substr(4, 4)}-${`${i}`.substr(8, 4)}`; | |
} | |
} | |
const uuid2 = UUIDGenerator(); | |
for (let i = 0; i < 10001; i++) { | |
console.log(uuid2.next().value) // 1000-0000-0000 -> 1000-0001-0000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment