生成非常大的随机数Java [英] Generating very large random numbers java

查看:480
本文介绍了生成非常大的随机数Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在Java中生成非常大的随机数?我说的是10000位数吗?我知道我们必须使用BigInteger,但是我们该怎么做呢?做这样的事情最有效的方法是什么?请提供一个小例子.谢谢.

How can we generate very large random number in java? I am talking something like 10000 digits? I know we have to use BigInteger but how can we do this? What is the most efficent way of doing something like this? Please provide a small example. Thank you.

推荐答案

好吧,一种方法是转到 Random.org 并下载二进制随机文件之一.这些文件是由大气噪声生成的,因此它是非常随机的.我在国际象棋引擎中将它用于Zobrist键.

Well, one way is to go to Random.org and download a one of the binary random files. The files are generated from atmospheric noise, so it's very random. I used it for Zobrist keys in my chess engine.

或者,你可以去

BigInteger b = new BigInteger(256, new Random());

这将给您您想要的.在此示例中,一个由256位组成的BigInteger.

which will give you what you want. In this example, a BigInteger consisting of 256 bits.

这篇关于生成非常大的随机数Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆