How to generate 8 bytes unique id from GUID?

后端 未结 10 1661
长情又很酷
长情又很酷 2020-12-04 01:21

I try to use long as unique id within our C# application (not global, and only for one session) for our events. Do you know if the following will generate an unique long id?

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 02:12

    As already said in most of the other answers: No, you can not just take a part of a GUID without losing the uniqueness.

    If you need something that's shorter and still unique, read this blog post by Jeff Atwood:
    Equipping our ASCII Armor

    He shows multiple ways how to shorten a GUID without losing information. The shortest is 20 bytes (with ASCII85 encoding).

    Yes, this is much longer than the 8 bytes you wanted, but it's a "real" unique GUID...while all attempts to cram something into 8 bytes most likely won't be truly unique.

提交回复
热议问题