Collisions when generating UUIDs in JavaScript?

前端 未结 6 1852
遥遥无期
遥遥无期 2020-11-28 20:12

This relates to this question. I am using the code below from this answer to generate UUID in JavaScript:

\'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\'.replace(/[         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 20:56

    My best guess is that Math.random() is broken on your system for some reason (bizarre as that sounds). This is the first report I've seen of anyone getting collisions.

    node-uuid has a test harness that you can use to test the distribution of hex digits in that code. If that looks okay then it's not Math.random(), so then try substituting the UUID implementation you're using into the uuid() method there and see if you still get good results.

    [Update: Just saw Veselin's report about the bug with Math.random() at startup. Since the problem is only at startup, the node-uuid test is unlikely to be useful. I'll comment in more detail on the devoluk.com link.]

提交回复
热议问题