vendredi 6 février 2015

How to create a 64 bit Unique Integer in Java?

I need to create a 64 bit Unique Integer in Java so that collision chances are pretty less.


Is there any way, we can create a 64 bit integer in Java which is always Unique?


As of now I am using -



long number = System.nanoTime();


Is this the right way to generate 64 bit Unique Integer in Java or is there anything else I can try?


UPDATE:-


How about doing this way? Will this be unique?



UUID number = UUID.randomUUID();
long uniqueNumber = number.timestamp();




Aucun commentaire:

Enregistrer un commentaire