UUID to unique integer id?

前端 未结 6 758
悲哀的现实
悲哀的现实 2021-01-01 08:37

I was wondering what the easiest way to convert a UUID to a unique integer would be? I have tried using the hash code but people tell me that it is not going to always be un

6条回答
  •  醉酒成梦
    2021-01-01 08:54

    A UUID is a 16-Byte number (128 bit). You can't crunch it into an int (32 bit) while preserving it's uniqueness.

    Mathematically spoken: 296 UUIDs will share the same Java-int-size hash value (which is ... a lot ;) )

    A way out - some real life UUID often have a rather static part. So in isolated scenarios, the real unique portion of UUIDs may be less then 32 bit.

提交回复
热议问题