基于正态分布的范围内的随机数 [英] Random number within a range based on a normal distribution

查看:291
本文介绍了基于正态分布的范围内的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成一个范围为n到m,例如100到150的随机数,但是我希望结果不是基于随机数,而是基于正态分布.

I want to generate random numbers with a range (n to m, eg 100 to 150), but instead of purely random I want the results to be based on the normal distribution.

我的意思是说,我通常希望数字聚集"在125左右.

By this I mean that in general I want the numbers "clustered" around 125.

我发现了这个随机数软件包,它似乎有很多需要: http ://codeproject.com/KB/recipes/Random.aspx

I've found this random number package that seems to have a lot of what I need: http://codeproject.com/KB/recipes/Random.aspx

它支持各种随机生成器(包括麻扭曲器),并且可以将生成器应用于发行版.

It supports a variety of random generators (include mersiene twister) and can apply the generator to a distribution.

但是我很困惑,如果我使用正态分布生成器,那么随机数大约是-6到+8(显然,真正的范围是float.min到float.max).

But I'm confused, if I use a normal distribution generator the random numbers are from roughly -6 to +8 (apparently the true range is float.min to float.max).

如何缩放到我所需的范围?

How do a scale that to my required range?

推荐答案

标准正态分布的均值为0,标准差为1;如果要使用均值m和偏差s进行分布,只需将其乘以s,然后加m.由于理论上的正态分布是无限的,因此您不能在范围上设置硬上限,例如(100〜150),而不明确地拒绝落在其外部的数字,但带偏差的适当选择可以放心,(例如)你的号码的99%将是的范围内.

A standard normal distribution has mean 0 and standard deviation of 1; if you want to make a distribution with mean m and deviation s, simply multiply by s and then add m. Since the normal distribution is theoretically infinite, you can't have a hard cap on your range e.g. (100 to 150) without explicitly rejecting numbers that fall outside of it, but with an appropriate choice of deviation you can be assured that (e.g.) 99% of your numbers will be within the range.

大约99.7%的总体误差在+/- 3个标准差之内,因此,如果您选择的标准偏差在(25/3)左右,则它应该可以正常工作.

About 99.7% of a population is within +/- 3 standard deviations, so if you pick yours to be about (25/3), it should work well.

所以您想要类似的东西:(normal * 8.333) + 125

So you want something like: (normal * 8.333) + 125

这篇关于基于正态分布的范围内的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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