Java中random生成概率,如何在Java中生成所有可能的64位随机值?

Does Java SecureRandom.nextLong() return all possible values given it inherits from Random which uses only 48 bits? If not, can I still do it in Java maybe by modifying the Random class and how to do it? I just want to use an all random long number generator where all possible long values can be returned, if possible.

解决方案

While SecureRandom inherits from Random, it doesn't use the same maths or have the same limitation. It will produce all possible 64-bit values eventually.

This class provides a cryptographically strong random number generator (RNG).

This class delegates to one of many possible implementations. You can select one by calling SecureRandom.getInstance(algorithm)

Note: some implementations use entropy in your computer to make the results random, rather than purely pseudo random.

this uses s 48 bit algorighm

SecureRandom doesn't use any of the methods of it's parent e.g.

/**

* The provider implementation.

*/

private SecureRandomSpi secureRandomSpi = null;

public void nextBytes(byte[] bytes) {

secureRandomSpi.engineNextBytes(bytes);

}

This method delegates to a completely different implementation.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值