我正在使用UUID.randomUUID().getLeastSignificantBits();生成唯一ID.但是,我想每次运行应用程序时生成相同的ID,以便调试我的代码.我怎样才能做到这一点?
编辑:感谢zim-zam我创建了这个解决问题的类.
public class IDGenerator {
private static Random random = new Random(1);
public static long getID() {
long id;
byte[] array = new byte[16];
random.nextBytes(array);
id = UUID.nameUUIDFromBytes( array ).getLeastSignificantBits();
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用从种子或种子UUID.nameUUIDFromBytes(byte[] bytes)到达的地方byte[] bytesRandomSecureRandom
| 归档时间: |
|
| 查看次数: |
806 次 |
| 最近记录: |