Random.nextGaussian() 的问题 [英] problem with Random.nextGaussian()
问题描述
Random.nextGaussian() 应该给出均值为 0 且标准差为 1 的随机数.它生成的许多编号都在 [-1,+1] 的范围之外.我如何设置以便它只在 -1 到 1 的范围内给出正态分布的随机数.
Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives normally distributed random no.s only in the range -1 to 1.
推荐答案
均值为 0 且标准差为 1 的高斯分布意味着分布的平均值为 0 并且大约 70% 的总体位于 [-1, 1].忽略超出范围的数字——它们在两边形成大约 16% 的边缘.
A Gaussian distribution with a mean 0 and standard deviation one means that the average of the distribution is 0 and about 70% of the population lies in the range [-1, 1]. Ignore the numbers that are outside your range -- they form the fringe 16% approx on either side.
也许更好的解决方案是生成具有 mean=0
和 std.dev=0.5
的分布.这将为您提供大约 96% 的值在 [-1, 1] 范围内的分布.
Maybe a better solution is to generate a distribution with mean=0
and std.dev=0.5
. This will give you a distribution with about 96% of the values in the range [-1, 1].
一个更好的解决方案是像上面那样向后工作,并使用大约99.7% 的值位于 3-sigma 范围内:使用 std.dev = 1/3
.这几乎会使您获得的不那么有用的值的数量无效.当你得到一个时,省略它.
An even better solution is to work backward as above and use the idea that approx. 99.7% of the values lie in the 3-sigma range: use a std.dev = 1/3
. That will almost nullify the amount of not-so-useful values that you are getting. When you do get one, omit it.
当然,如果您正在开发数学密集型产品,所有这些都没有任何价值.
Of course, if you are working on a math intensive product, all of this bears no value.
这篇关于Random.nextGaussian() 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!