伪随机数发生器 - 指数分布随机数、发生器、指数

2023-09-10 22:31:36 作者:恋雪

我想产生一些伪随机数和到现在为止我已经非常知足了。NET库的 Random.Next(INT分钟,INT最大)功能。该品种的PRNG是的应该的使用均匀分布,但我非常想使用指数分布产生一些数字。

I would like to generate some pseudorandom numbers and up until now I've been very content with the .Net library's Random.Next(int min, int max) function. PRNGs of this variety are supposed to be using a Uniform distribution, but I would very much like to generate some numbers using an Exponential Distribution.

我在C#编程,不过我会接受伪code或C ++,Java或类似。

I'm programming in C#, although I'll accept pseudocode or C++, Java or the like.

任何建议/ code片段/算法/想法?

Any suggestions / code snippets / algorithms / thoughts?

推荐答案

既然你有机会到一个统一的随机数发生器,产生一个随机数分布与其他分布的CDF你知道是很容易使用的反演方法

Since you have access to a uniform random number generator, generating a random number distributed with other distribution whose CDF you know is easy using the inversion method.

于是,产生均匀的随机数, U [0,1),然后计算 X 是:

So, generate a uniform random number, u, in [0,1), then calculate x by:

X =日志(1-U)/(&负;&拉姆达;

x = log(1-u)/(−λ),

在这里和拉姆达;是指数分布的速率参数。现在, X 是一个随机数与指数分布。需要注意的是日志上面 LN ,自然对数。

where λ is the rate parameter of the exponential distribution. Now, x is a random number with an exponential distribution. Note that log above is ln, the natural logarithm.

 
精彩推荐
图片推荐