伪随机数生成器 - 指数分布 [英] Pseudorandom Number Generator - Exponential Distribution

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

问题描述

我想生成一些伪随机数,到目前为止,我对 .Net 库的 Random.Next(int min, int max) 函数非常满意.这种类型的 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# 编程,尽管我会接受伪代码或 C++、Java 或类似的东西.

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

任何建议/代码片段/算法/想法?

Any suggestions / code snippets / algorithms / thoughts?

推荐答案

由于您可以使用统一随机数生成器,因此可以使用 反演方法.

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.

因此,在[0,1)中生成一个统一的随机数u,然后通过以下方式计算x:

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

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

其中 λ 是指数分布的速率参数.现在,x 是一个指数分布的随机数.注意上面的logln,自然对数.

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.

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

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