偏置随机数发生器 [英] Biased Random Number Generator

查看:159
本文介绍了偏置随机数发生器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个可以有偏见的随机数生成器。例如,假设我想要一个1-5之间的随机数,概率为:

I am looking for a random number generator that can be biased. For instance, say I want a random number between 1-5, with the probability being:

1:达到20%的时间

2:达到10%的时间

3:达到40%的时间

4:达到25%的时间

5:达到5%的时间

1: Comes up 20% of the time
2: Comes up 10% of the time
3: Comes up 40% of the time
4: Comes up 25% of the time
5: Comes up 5% of the time

标准库中有什么东西,或者其他图书馆会有这样做吗?

Is there anything in the standard library, or other libraries out there that would do this? Alternatively, is there an efficient way to do this myself?

推荐答案

Boost随机数库提供了指定不同形状分布的能力为您的发电机。这是一个很棒的图书馆 - 请参阅 http://www.boost.org/doc/libs/ 1_42_0 / libs / random / index.html

The Boost random number library provides the ability to specify different shaped distributions for your generator. It's a great library - see http://www.boost.org/doc/libs/1_42_0/libs/random/index.html.

这篇关于偏置随机数发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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