在需要重新设定种子之前,可以使用randomGenerator.nextDouble()多少次? [英] How many times can I use randomGenerator.nextDouble() before I need to reseed?
问题描述
我将Java中的Random
类用作伪随机数生成器.我多次使用了nextDouble函数(〜10 ^ 5).我必须重新播种多少次才能防止获得相同的数字?是否需要播种?
I'm using the Random
class in Java as a pseudo-random number generator. I'm using the function nextDouble a lot of times (~10^5). How many times before I have to reseed to prevent from getting the same numbers? Is reseeding needed?
Random generator = new Random();
double[] numbers = new double[n];
for (int i = 0; i < n; i++) numbers[i] = generator.nextDouble();
这是一个实验,数字将用作空间上各个点的坐标,所以我希望分布尽可能均匀.
This is for an experiment, the numbers will be used as coordinates for points on a space, so I want the distribution to be as uniform as possible.
我该如何播种?我从哪里得到int种子?
Also how do I reseed? Where do I get the int seed from?
推荐答案
随机数生成器将从两个随机int值中生成一个随机double.内部种子具有48位,因此随机序列最多在2 ^ 48个int值或2 ^ 47个double值之后重复.
The random number generator will produce a random double from two random int values. The internal seed has 48 bit, so the random sequence repeats after at most 2^48 int values, or 2^47 double values.
这篇关于在需要重新设定种子之前,可以使用randomGenerator.nextDouble()多少次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!