JavaScript Math.random 正态分布(高斯钟形曲线)? [英] JavaScript Math.random Normal distribution (Gaussian bell curve)?

查看:25
本文介绍了JavaScript Math.random 正态分布(高斯钟形曲线)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 JavaScript 函数 Math.random 是否使用正态(与均匀)分布.

I want to know if the JavaScript function Math.random uses a normal (vs. uniform) distribution or not.

如果没有,我怎样才能得到使用正态分布的数字?我还没有在网上找到明确的答案,一种创建随机正态分布数的算法.

If not, how can I get numbers which use a normal distribution? I haven't found a clear answer on the Internet, for an algorithm to create random normally-distributed numbers.

我想重建施密特机(德国物理学家).机器产生 0 或 1 的随机数,并且它们必须是正态分布的,这样我才能将它们绘制为高斯钟形曲线.

I want to rebuild a Schmidt-machine (German physicist). The machine produces random numbers of 0 or 1, and they have to be normally-distributed so that I can draw them as a Gaussian bell curve.

例如,随机函数产生 120 个数字(0 或 1),并且这些总和值的平均值(均值)必须接近 60.

For example, the random function produces 120 numbers (0 or 1) and the average (mean) of these summed values has to be near 60.

推荐答案

我想知道 JavaScript 函数 Math.random 是否是正态分布

I want to know if the JavaScript function Math.random is normal distribution or not

Javascript Math.random is not 正态分布(高斯钟形曲线).来自 ES 2015, 20.2.2.27 返回带有正号的数值,大于或等于 0 但小于 1,使用依赖于实现的算法或策略随机或伪随机选择在该范围内近似均匀分布.此函数不接受任何参数."所以当 n 足够高时提供的集合我们将得到近似均匀的分布.区间内的所有值出现的概率相等(与x轴平行的直线,表示0.0到1.0之间的数字).

Javascript Math.random is not a Normal Distribution(Gaussian bell curve). From ES 2015, 20.2.2.27 "Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments." So the provided collection when n is high enough we will get approximately uniform distribution. All values in the interval will have equal probability of appearance(straight line parallel to the x axis, denoting number between 0.0 and 1.0).

如何得到正态分布的数字

how can I get numbers which are normal distribution

有几种方法可以获取正态分布的数字集合.正如 Maxwell Collard 所回答的,Box-Muller 变换确实将均匀分布转换为正态分布(代码可以在 Maxwell Collard 答案 中找到).

There are several ways of getting collection of numbers with a normal distribution. As answered by Maxwell Collard the Box-Muller transform does transform uniform distribution to normal distribution(the code can be found in Maxwell Collard answer).

另一个 stackoverflow 对 问题的回答对正态分布算法有其他均匀分布的回复.如:金字形神塔,制服比例,反转 CDF除了其中一个答案说: 说:

An answer to another stackoverflow answer to a question has a reply with other uniform distribution to normal distribution algorithms. Such as: Ziggurat, Ratio-of-uniforms, Inverting the CDF Besides one of the answers says that: says:

Ziggurat 算法在这方面非常有效,尽管 Box-Muller 变换更容易从头开始实现(并且不会太慢).

The Ziggurat algorithm is pretty efficient for this, although the Box-Muller transform is easier to implement from scratch (and not crazy slow).

最后

我想重建施密特机(德国物理学家),机器产生 0 或 1 的随机数,它们必须是正态分布的,这样我才能用高斯钟形曲线绘制它们.

I want to rebuilt a Schmidt-machine (German physicist), the machine produces random numbers of 0 or 1 and they have to be normal distributed so I can draw them in Gaussian bell curve.

当我们只有两个值(0 或 1)时,高斯曲线看起来与具有 2 个可能值的均匀分布相同.这就是为什么一个简单的

When we have only two values (0 or 1) Gaussian curve looks the same as uniform distribution with 2 possible values. That is why a simple

function randomZero_One(){
    return Math.round(Math.random());
}

就够了.它将以近似相等的概率值 0 和 1 伪随机返回.

would suffice. It would return pseudo-randomly with approximately equal probability values 0 and 1.

这篇关于JavaScript Math.random 正态分布(高斯钟形曲线)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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