0

I am doing R&D on getting unique device ID for android device but none of the solution seems perfect.

UUID.randomUUID().toString(); seems a good solution but I am wondering that in each call does this function return unique value? If it is true than it is good else I think it is also not a good solution.

R&D links on getting unique device ID: 1: http://www.ssaurel.com/blog/how-to-retrieve-an-unique-id-to-identify-android-devices/ 2: Is there a unique Android device ID?

Furqan
  • 787
  • 2
  • 13
  • 28
  • 2
    Possible duplicate of [how good is java's UUID.randomUUID?](https://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid) – Henry Oct 13 '17 at 08:26
  • 1
    Don't ask yourself "how to avoid duplicates?" Ask yourself "how will the system behave if duplicates occur?" Will everything suddenly break down if someone steals someone's else UUID? If not, don't bother with trying to avoid duplicates, but apply reasonable efforts to alleviate their effects. – user1643723 Oct 13 '17 at 10:08

2 Answers2

3

There are four different basic types of UUIDs:

Time-based, DCE security, name-based, and randomly generated UUIDs.

As far as chances are concerned, yes there is a possibility for same UUID for 2 devices. You can make it by other ways. For example

1) Get the UUID first and appened date time with it that will make completely unique id

2)Get the UUID first and appened date time and also append IMEI nuber with it that will make completely unique id

For more information regarding UUID you may refer below link

http://tools.ietf.org/rfc/rfc4122.txt

crgarridos
  • 8,758
  • 3
  • 49
  • 61
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • Thanks for you answer. – Furqan Oct 13 '17 at 06:10
  • 1: Get the UUID first and appened date time with it that will make completely unique id. [I think there is still probability it will same for two different devices ] – Furqan Oct 13 '17 at 06:11
  • This would be a waste of time. – user94559 Oct 13 '17 at 06:11
  • @smarx so what is the perfect solution here? – Furqan Oct 13 '17 at 06:12
  • Just use the UUID. – user94559 Oct 13 '17 at 06:13
  • It will not same for two different calls ever? – Furqan Oct 13 '17 at 06:15
  • There's some minuscule chance of a collision, so I guess it would be wrong to say "no," but... no. :-) I'm trying to find a good source for the math, but as I recall, if you generated 1,000 GUIDs a second for the next year, the odds are higher that you'd be hit in the head with a meteorite than that you'd find a collision. – user94559 Oct 13 '17 at 06:17
  • 1
    http://ralphbecket.blogspot.com/2011/09/birthday-paradox-and-guid-collisions.html says if you made "one million billion" random UUIDs, you'd have a roughly 1 in a billion chance of finding a collision. You're going to make many fewer UUIDs than that. – user94559 Oct 13 '17 at 06:19
  • Thank you very much :) It helps alot. – Furqan Oct 13 '17 at 06:21
  • 1
    Unless I did [the birthday paradox](https://en.wikipedia.org/wiki/Birthday_problem) math wrong, I think there's about a 1/1,000,000,000,000,000,000,000 chance of finding a collision if you give everyone in the world a UUID. (*n* = 8 billion people, and *d* = 2^128 possible UUIDs) – user94559 Oct 13 '17 at 06:25
  • @smarx Wrong! You are forgetting, that only some of 128 bits are random. 6's and 8's bytes are not random. Also low-probability != impossible. – user1643723 Oct 13 '17 at 09:53
  • @user1643723 Ah, so my math *is* wrong! Feel free to provide the right number (using d=2^122, I believe, if I'm reading [the Wikipedia article](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) properly); it's still going to be astronomically unlikely to find a collision. (My original claim that you're more likely to be hit by a meteorite than find a collision should still be true by a wide margin.) – user94559 Oct 13 '17 at 10:13
1

For all practical purposes the result of UUID.randomUUID() is unique. However, since there are only finitely many UUIDs it is clear that there will be repetitions eventually.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • We can use it for uniquely identify our device? What is the probability that it will same for two different devices? – Furqan Oct 13 '17 at 05:58