3
I have today an application that is presenting data divergence because of the return time of a webservice.
To get around this we created a code to prevent this particular information from ever repeating, until then everything right is working.
I need to generate a 10-digit identification code, which is not repeated on other tablets that use my application. Because it can compromise the data in the system.
How can I generate a 10-digit random alphanumeric code that does not repeat itself, using Java?
Why don’t you use the
UUID
of the device?– Wakim
every hour I submit a piece of information, in case a service order I need a different code.
– Hiago Souza
Even if they are 10 random digits, there is a chance that the device A and B will generate the same. The idea of @Wakim would solve your problem, because this
UUID
is unique, I think.– emanuelsn
Since each request needs to be unique, it could salt the
UUID
with atimestamp
and generate an MD5. the MD5 can be optional believe.– Wakim
Yes I thought about it, but the service only accepts up to 10 characters in this location.
– Hiago Souza
Now thinking here, if I generate MD5 and give break the string in up to 10 characters would work.
– Hiago Souza
I think making substring of MD5 is not a good solution, because prefixes can repeat, even MD5 has collisions. I saw that there is the
ANDROID_ID
(http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID), which is a 64-bit number, which is unique to each user/device.– Wakim
@Wakim thank you, if you want to put as an answer for me to mark as correct. Ai you complement to take the timestamp the uuid and generate the md5 and take only the top 10 positions of the returned string.
– Hiago Souza
@Hiagosouza, do not recommend using substring on
MD5
. TheMD5
already has a certain probability of collision, using substring will increase a lot (collision occurs when two values generate the same hash). The way is to look for an encryption algorithm that can generate exactly 10 digits, in order not to increase the collisions.– Wakim