需要帮助从分布中生成离散的随机数 [英] Need help generating discrete random numbers from distribution

查看:100
本文介绍了需要帮助从分布中生成离散的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了该站点,但没有确切找到我要寻找的东西...我想从正态分布中生成一个离散的随机数.

例如,如果我的最小范围是4,最大范围是10,平均范围是7.我需要什么代码或函数调用(优选Objective C)返回该范围内的数字.自然,由于正态分布,返回的更多数字将以平均值7为中心.

作为第二个示例,钟形曲线/分布是否可以偏向另一端?可以说,我需要生成一个随机数,其范围最小为4,最大为10,并且我希望大多数数字以偏斜的钟形曲线自然下降为返回数字8的中心.

非常感谢您的帮助....

安东尼

解决方案

您需要什么?你能做到掷骰子的方式吗?

生成2到5(当然包括端值)范围内的两个随机整数,并将它们加在一起.或将硬币(0,1)翻转六次,并将结果加4.

对多个骰子求和会产生正态分布(钟形曲线"),同时消除了高掷或低投均可用于以各种方式歪曲分布.

关键是您要输入离散数字(我希望您的意思是整数).多次掷骰子会产生正态分布.实际上,我认为这就是我们第一次被引入学校的高斯曲线的方式.


当然,掷得越多,您越接近钟形曲线.滚动单个模具会产生一条平线.掷两个骰子只会产生与铃铛不太接近的向上和向下倾斜.六次硬币翻转使您更近.

所以考虑一下...

如果我正确理解了您的问题,那么您只有七个可能的结果-整数(4,5,6,7,8,9,10).您可以设置一个由七个概率组成的数组,以近似您喜欢的任何分布.

I searched the site but did not find exactly what I was looking for... I wanted to generate a discrete random number from normal distribution.

For example, if I have a range from a minimum of 4 and a maximum of 10 and an average of 7. What code or function call ( Objective C preferred ) would I need to return a number in that range. Naturally, due to normal distribution more numbers returned would center round the average of 7.

As a second example, can the bell curve/distribution be skewed toward one end of the other? Lets say I need to generate a random number with a range of minimum of 4 and maximum of 10, and I want the majority of the numbers returned to center around the number 8 with a natural fall of based on a skewed bell curve.

Any help is greatly appreciated....

Anthony

解决方案

What do you need this for? Can you do it the craps player's way?

Generate two random integers in the range of 2 to 5 (inclusive, of course) and add them together. Or flip a coin (0,1) six times and add 4 to the result.

Summing multiple dice produces a normal distribution (a "bell curve"), while eliminating high or low throws can be used to skew the distribution in various ways.

The key is you are going for discrete numbers (and I hope you mean integers by that). Multiple dice throws famously generate a normal distribution. In fact, I think that's how we were first introduced to the Gaussian curve in school.


Of course the more throws, the more closely you approximate the bell curve. Rolling a single die gives a flat line. Rolling two dice just creates a ramp up and down that isn't terribly close to a bell. Six coin flips gets you closer.

So consider this...

If I understand your question correctly, you only have seven possible outcomes--the integers (4,5,6,7,8,9,10). You can set up an array of seven probabilities to approximate any distribution you like.

这篇关于需要帮助从分布中生成离散的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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