前倾随机数概率分布

发布于 2024-11-29 06:16:23 字数 155 浏览 1 评论 0原文

假设我在 100 秒内每秒伪随机地选择一个从 1 到 50 的数字,并且随着时间的推移,选择的数字更有可能更大。我如何构建这样的算法?

例如:99秒后选择接近50的数字的可能性比选择接近1的数字的可能性大得多。

或者:10秒后选择的数字更有可能大于9秒后选择的数字

Say I'm pseudo-randomly picking a number from 1 to 50 every second for 100 seconds, and as time goes on the number picked is more likely to be greater. How could I structure such an algorithm?

For example: after 99 seconds the probability of choosing a number closer to 50 is much more likely than choosing a number closer to 1.

Or: the number picked after 10 seconds is more likely to be greater than the number picked after 9 seconds

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情释 2024-12-06 06:16:23

选择任何凹单调函数,如平方根,将 0 映射到 0,将 1 映射到 1。生成 [0,1] 之间的随机数,应用该函数,然后将 [0,1] 拉伸到所需的区间 ([1,50] )。

现在,如果您使用简单的权重从线性变换 f(x)=x 转变为提到的变换函数,您将获得所需的效果。

Pick any concave monotonic function like square root which maps 0 to 0 and 1 to 1. Generate a random number between [0,1], apply the function and then scretch [0,1] to the desired interval ([1,50]).

Now if you morph from the linear transformation f(x)=x to the mentioned transform function with for example a simple weighting you have the desired effect.

陈年往事 2024-12-06 06:16:23

我有一个简单的解决方案给你。使用此表达式代替 rand(1, 50) (假设此函数生成均匀随机数 1..50):

power(rand(1, power(50, exp)), 1/exp)

这仍将为您提供所有数字 1..50。对于 exp = 1,分布将是均匀的。当你稍微增加exp(例如1.1左右)时,获得更大数字的概率将会增加。 exp 越高,它就会增加到 50。

所以你可以这样做,例如:

factor = 1 /* finetune this for your needs */
for second = 0..100
    exp = 1 + (second / 100) * factor
    rand_num = power(rand(1, power(50, exp)), 1/exp)
endfor

I have a simple solution for you. Instead of rand(1, 50) (say this function generates uniformly random numbers 1..50) use this expression:

power(rand(1, power(50, exp)), 1/exp)

this will still give you all the numbers 1..50. For exp = 1, the distribution will be uniform. As you slightly increase exp (e.g. like 1.1 or so), the probability of getting larger numbers will increase. The higher the exp, the more it will increase towards 50.

So you can do e.g.:

factor = 1 /* finetune this for your needs */
for second = 0..100
    exp = 1 + (second / 100) * factor
    rand_num = power(rand(1, power(50, exp)), 1/exp)
endfor
小ぇ时光︴ 2024-12-06 06:16:23

伪代码:

let i = 0
let n = 50 // Adjust for your needs
for i goes to 100 {
  randomnum = int(sqrt(rand(1, 50*n)));
}

这可能非常具有前瞻性,但这是实现它的一种方法。

感谢 Ricky Bobby 指出了我的旧方法的一个根本问题。这是受到 yi_H 使用 sqrt 这样的函数的建议的启发。

Pseudocode:

let i = 0
let n = 50 // Adjust for your needs
for i goes to 100 {
  randomnum = int(sqrt(rand(1, 50*n)));
}

This can be very forward-leaning, but it's one way to approach it.

Thanks to Ricky Bobby for pointing out a fundamental problem with my old approach. This is inspired by yi_H's suggestion of using a function like sqrt.

美人如玉 2024-12-06 06:16:23

对于您正在做的事情可能有更简单的方法,但一般的解决方案是使用逆变换采样

本质上,如果您想使用给定的 PDF p(x) 生成随机数,您首先需要计算逆累积密度函数 (CDF),P'(x) >。然后,您可以生成 0 到 1 之间的均匀随机数,然后将 P'(x) 应用于它们。

There are probably simpler ways for what you're doing, but the general solution is to use inverse transform sampling.

Essentially, if you want to produce a random number with a given PDF, p(x), you first calculate the inverse cumulative density function (CDF), P'(x). You can then generate uniform random numbers between 0 and 1, and then apply P'(x) to them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文