产生幂律分布的随机数发生器? [英] Random number generator that produces a power-law distribution?

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

问题描述

我正在为C ++命令行Linux应用程序编写一些测试。我想生成一束具有幂律/长尾分布的整数。意思,我得到一些数字很频繁,但大多数是相对不频繁。



理想情况下,只有一些魔术方程式,我可以使用rand()或stdlib随机函数。如果没有,一个容易使用的C / C ++的块将是巨大的。



谢谢!

解决方案

这篇在Wolfram MathWorld 的页面讨论了如何从均匀分布获得幂律分布(这是大多数随机数发生器提供的)。



简短的回答(上述链接的派生):

  x = [(x1 /(n + 1)-x0 ^(n + 1))* y + x0 ^ ))

其中 y 是统一变量, / strong>是分布函数, x0 x1 定义分布的范围, x 是您的幂律分布变量。 / p>

I'm writing some tests for a C++ command line Linux app. I'd like to generate a bunch of integers with a power-law/long-tail distribution. Meaning, I get a some numbers very frequently but most of them relatively infrequently.

Ideally there would just be some magic equations I could use with rand() or one of the stdlib random functions. If not, an easy to use chunk of C/C++ would be great.

Thanks!

解决方案

This page at Wolfram MathWorld discusses how to get a power-law distribution from a uniform distribution (which is what most random number generators provide).

The short answer (derivation at the above link):

x = [(x1^(n+1) - x0^(n+1))*y + x0^(n+1)]^(1/(n+1))

where y is a uniform variate, n is the distribution power, x0 and x1 define the range of the distribution, and x is your power-law distributed variate.

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

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