gpt4 book ai didi

java - UUID.randomUUID().getLeastSignificantBits() 总是返回负值?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:17:44 31 4
gpt4 key购买 nike

我需要生成一个唯一的 long 值,所以我决定使用 UUID:

UUID.randomUUID().getLeastSignificantBits();

我注意到一件奇怪的事情是 UUID.randomUUID().getLeastSignificantBits() 总是返回负值。我很迷惑。我错过了什么吗?

最佳答案

Wikipedia says :

Version 4 UUIDs use a scheme relying only on random numbers. This algorithm sets the version number (4 bits) as well as two reserved bits. All other bits (the remaining 122 bits) are set using a random or pseudorandom data source.

Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B

所以最低有效部分的第一位将始终为 1,使其成为负数。

关于java - UUID.randomUUID().getLeastSignificantBits() 总是返回负值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26747292/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com