Re:Show HN: Givemeguid.com – CLI/curl friendly GUIDs
by tatersolid on Thursday June 18, 2020 @08:40AM
(#23562502)
JavaScript Math.random() should never be used for UUID generation. You will get collisions even at small scale.
window.crypto.getRandomValues() should be used instead.
The quality and seeding of Math.random() is implementation-dependent and not generally good enough everywhere to prevent collisions. Many seed with the just the system time.
Source: I have personally seen such collisions in a production web app with 700k users. A Web search for “Javacsript GUID collision” shows that many others have as well. We switched to the cryptographic generator and the collisions disappeared.
Re:Show HN: Givemeguid.com – CLI/curl friendly GUIDs
by sk0g on Tuesday June 16, 2020 @05:06AM
(#23537200)
UUIDs also have a hashed namespace in them, don't they? Not sure if that version implements them.
Re:Show HN: Givemeguid.com – CLI/curl friendly GUIDs
by hombre_fatal on Tuesday June 16, 2020 @05:35AM
(#23537314)
Only uuid v3/v5. Anything is possible if that's what you want. But 128 (or 122) bits of random are usually what you want when you think of guid.
Most people format 128-bit random numbers into a UUID just so it's obvious at a glance what it is: a guid. Even if it's not technically a UUIDv4 because it doesn't have the magic bits.
https://gist.github.com/jed/982883
If you google "generate uuid javascript" you can find approaches from Math.random to node/browser `crypto` module to shelling out OS random.
One of the main benefits of guid generation is that you don't need to synchronize with anything to generate a unique ID, so it's weird to incur an http request, especially to someone else's service. At that point you might as well just phone home to your own service.