获得范围(x,y)中的随机BigInteger [英] get random BigInteger in range (x, y)
本文介绍了获得范围(x,y)中的随机BigInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取一个大于2 ^ 511且小于2 ^ 512的随机BigInteger.
I need to get a random BigInteger that is bigger than 2^511 and lower than 2^512.
推荐答案
byte[] bytes = new byte[64]; // 512 bits
new Random().nextBytes(bytes);
bytes[0] |= 0x80; // set the most significant bit
return new BigInteger(1, bytes);
这篇关于获得范围(x,y)中的随机BigInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文