Check broofa’s site for the most up to date:

http://www.broofa.com/blog/2008/09/javascript-uuid-function/

]]>But sometimes you don’t have unique state to use as a starting point, as is the case in JavaScript. We don’t know the system’s MAC address or anything else that is sufficiently unique for our purposes. So instead we use state that we *hope* is unique – randomly generated numbers – to produce “version 4” UUIDs. As long as there is a sufficient degree of randomness, the odds of picking the same UUID are so astronomically low that we can essentially guarantee uniqueness for all but the most insanely picky requirements. (See my original blog post for details).

There is a catch, however, and that is that Math.random() typically relies on a pseudo-RNG algorithm. If you really want to get nit-picky about how unique the UUIDs we’re generating are, than you need to look at the quality of the algorithm and how it is seeded. But that’s really getting into microscopic hair-splitting, IMHO.

]]>