在生成正态分布的随机值时,定义范围的最有效方法是什么? [英] when generating normally-distributed random values, what is the most efficient way to define the range?

查看:150
本文介绍了在生成正态分布的随机值时,定义范围的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FYI:random == pseudo-random

FYI: random == pseudo-random

A。当生成均匀随机数时,我可以指定一个范围,即:

A. when generating uniformly-random numbers, I can specify a range, i.e.:

(Math.random()-Math.random())*10+5
//generates numbers between -5 and 15

B.使用高斯式正态随机性版本生成一组随机值:

B. generating a set of random values with a version of Gaussian-esque normal randomness:

//pass in the mean and standard deviation
function randomNorm(mean, stdev) {
  return Math.round((Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1))*stdev+mean);
}

//using the following values:
{
  mean:400, 
  standard_deviation:1
  //results in a range of 397-403, or +-range of 3
},
{
  mean:400, 
  standard_deviation:10
  //results in a range of 372-429, or +-range of 30
},
{
  mean:400, 
  standard_deviation:25
  //results in a range of 326-471, or +-range of 75
}

每一个给我一系列近似standard_deviation *( + -3)(假设我让程序运行的时间更长)。

each one gives me a range of approximately standard_deviation*(+-3) (assuming I left the program running longer).

C.我可以按如下方式计算这个范围:

C. I can calculate this range as follows:


  1. 假设我想要一个300-500的范围,所以var total_range = 200;

  2. 我的意思是400,我的+ - 范围是total_range / 2(var r = 100)

  3. 所以standard_deviation是r / 3或者在这种情况下是33.333。

这似乎有效,但我不知道我在做什么数学所以我觉得自己像个白痴,这个解决方案感觉kludgy并不完全准确。

This seems to be working, but I have no idea what I'm doing with math so I feel like an idiot, this solution feels kludgy and not totally accurate.

我的问题:
是否有一些我正在跳舞的公式可以帮助我?我的要求如下:

My question: is there some formula that I'm dancing around that can help me here? my requirements are as follows:


  1. 必须能够准确定义一系列数字。

  2. 必须尽可能高效地在JavaScript中完成。

我想也许我很接近,但它并不存在。

I think maybe I'm close but it's not quite there.

推荐答案

减去两个随机数并没有给出正态分布,它会给出在零两边线性下降的数字。请参阅此小提琴中的红色图表:

Subtracting two random numbers doesn't give you a normal distribution, it will give you numbers that decline linearly on both sides of zero. See the red diagram in this fiddle:

http://jsfiddle.net/ Guffa / tvt5K /

要获得正态分布的良好近似值,请将六个随机数加在一起。请参阅小提琴中的绿色图表。

To get a good approximation of normal distribution, add six random numbers together. See the green diagram in the fiddle.

因此,要获得正态分布的随机数,请使用:

So, to get normally distributed random numbers, use:

((Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random()) - 3) / 3

此方法基于中心极限定理,概述为第二种方法: http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution

This method is based on the central limit theorem, outlined as the second method here: http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution

这篇关于在生成正态分布的随机值时,定义范围的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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