|
|
|
|
|
by hombre_fatal
2190 days ago
|
|
Why would you make an http request if you can just google a 3-line JS solution? You're just generating a large random number and formatting it as a UUID. 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. |
|
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.