赞
踩
1. 均匀分布随机数:
具体参见:System.Random Class
2. 高斯分布随机数:
高斯分布随机数有多种方法可以生成,这里的是采用均匀分布随机数比值的方法(Knuth,1981)。具体原理及算法流程参见 论文:Algorithms for randomness in the behavioral science: A tutorial (Marc Brysbaert, 1991)
- public double GetGaussianNumber(Random random)
- {
- double u1, a, z;
- do
- {
- u1 = random.NextDouble();
- double u2 = random.NextDouble();
- double v = 0.8578 * (2 * u2 - 1);
- z = v / u1;
- a = 0.25 * z * z;
- if(a < 1 - u1)
- {
- break;
- }
- }while(a > (0.259 / u1 + 0.35) || a > - System.Math.Log(u1));
- return z;
- }
这里利用概率分布的反函数生成指数分布随机数。详见:Algorithms for randomness in the behavioral science: A tutorial (Marc Brysbaert, 1991)
- public double GetExpDistNumber(Random random)
- {
- double u;
- do
- {
- u = random.NextDouble();
- }while(u == 0);
- return - System.Math.Log(u);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。