random - Collisions when generating UUIDs in JavaScript? -


this relates this question. using this answer generate uuid in javascript:

'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {     var r = math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);     return v.tostring(16); }); 

this solution appeared working fine, getting collisions. here's have:

  • a web-app running in google chrome.
  • 16 users.
  • about 4000 uuids have been generated in past 2 months these users.
  • i got 20 collisions - e.g. new uuid genereated today same 2 months ago (different user).

so questions are:

  1. what's causing issue?
  2. how can avoid it?

my best guess math.random() broken on system reason (bizarre sounds.) first report i've seen of getting collisions.

node-uuid has test harness can use test distribution of hex digits in code. if looks okay it's not math.random(), try substituting uuid implementation you're using uuid() method there , see if still results.

[update: saw veselin's report bug math.random() @ startup. since problem @ startup, node-uuid test unlikely useful. i'll comment in more detail on devoluk.com link.]


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -