我希望获得并非总是相同的随机数字,在我的代码中,我将获得所有-0.5
或全部0.5
,这正是我不想要的。我想要的是一些真正的可变性,例如可能是-0.1
和0.33
,可能还有-0.0666
- >你得到了图片 - 实际随机性!
我一直在寻找这个问题 - 如何在stackoverflow上找不到这些信息 - 我希望这个问题可以解决这个问题。
如果有人可以指明我的方式 - 如果他们能指出高斯分布随机性的方式 - 这将是美味的。
我的代码看起来像这样:
//MAKE SURE YOU HAVE ONE FOR BIAS
for (int j = 0; j < weights_one.length ; j++)
{
weights_one[j] = randoDub(0.5, 0.5);
}
for (int j = 0; j < weights_one.length ; j++)
{
System.out.println("weights_one[" + j + "]: " + weights_one[j]);
}
//now that we have inputs --> we must initialize the weight vectors
//then we do our calculation // our rule --> and then we are finished.
}
public static double randoDub(double min, double max) throws InterruptedException
{
Random rand = new Random( System.currentTimeMillis() );
double randomValue = min + (max - min) * rand.nextDouble();
//DELAY FOR SEED CHANGE
TimeUnit.SECONDS.sleep(5);
return randomValue;
}
答案 0 :(得分:2)
您使用min
和max
的相同参数调用randoDub(-0.5, 0.5)
。您可能需要randoDub(0.5, 0.5)
而不是Random
。
作为建议,要避免在函数内部睡觉,而是在randoDub
之外创建一个{{1}}对象并将其传入。