The uniqueness of UUID generated using Boost library vs Java

孤街浪徒 提交于 2021-02-05 08:55:07

问题


An Android app from my organization needs to assign each users an UUID(version 4) when they first launch the app, currently we're using Boost library 1.58.0 for this purpose, our Android app will use JNI to run the code below for generating UUIDv4:

boost::uuids::basic_random_generator<boost::random::lagged_fibonacci44497> generator;
generator(); //generating UUIDv4

The code worked fine for years, now we're deciding to replace it with an API in Java(UUID.randomUUID()). But we think it would be better if we can know about the uniqueness of these two ways before making the change.

My questions:

  1. Does the using of boost::random::lagged_fibonacci44497 reduce the chance of two devices using our app having the same UUID(collision)?
  2. If it is, can we know the probability of collision?
  3. Is that code better than UUID.randomUUID() in terms of uniqueness?

回答1:


The documentation for java.util.randomUUID() says the UUIDs it returns are "generated using a cryptographically strong pseudo random number generator". Thus, each such UUID will be almost certainly "unique" for most purposes (at least in Android versions after 4.3; see this question).

A version 4 UUID consists of 122 randomly chosen bits, so that there are at most 2^122 UUIDs of this kind. However, no randomly chosen value of finite length is guaranteed to be unique by itself.

Roughly speaking, when version 4 UUIDs are generated at random, the chance of accidental collision becomes non-negligible only after about 2^61 UUIDs are generated, which is about 2.7 billion billion (see "Birthday problem" for a precise statement and formulas).



来源:https://stackoverflow.com/questions/65531337/the-uniqueness-of-uuid-generated-using-boost-library-vs-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!