C++生成随机数:高斯/正态分布(gaussian/normal distribution)
来源:互联网 发布:sql中amount可以更新吗 编辑:程序博客网 时间:2024/05/22 14:36
高斯分布也称为正态分布(normal distribution)
常用的成熟的生成高斯分布随机数序列的方法由Marsaglia和Bray在1964年提出,C++版本如下:
#include <stdlib.h>#include <math.h> double gaussrand(){ static double V1, V2, S; static int phase = 0; double X; if ( phase == 0 ) { do { double U1 = (double)rand() / RAND_MAX; double U2 = (double)rand() / RAND_MAX; V1 = 2 * U1 - 1; V2 = 2 * U2 - 1; S = V1 * V1 + V2 * V2; } while(S >= 1 || S == 0); X = V1 * sqrt(-2 * log(S) / S); } else X = V2 * sqrt(-2 * log(S) / S); phase = 1 - phase; return X;}
这样生成的高斯分布随机数序列的期望为0.0,方差为1.0。若指定期望为E,方差为V,则只需增加:
X = X * V + E;
期望E= , 方差V=
wiki: http://zh.wikipedia.org/wiki/%E9%AB%98%E6%96%AF%E5%88%86%E5%B8%83
0 0
- C++生成随机数:高斯/正态分布(gaussian/normal distribution)
- C++生成随机数:高斯/正态分布(gaussian/normal distribution)
- 高斯分布(Gaussian distribution)/正态分布(Normal distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)与高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
- 机器学习小组知识点15:高斯分布/正态分布(Gaussian Distribution/Normal Distribution)
- 正态分布(Normal Distribution)
- Normal distribution & Gaussian distribution
- 截断正态分布(Truncated normal distribution)
- Normal distribution正态分布
- Boost库:多维变量联合高斯分布随机数(Multivariate Normal Distribution Boost)
- normal distribution, lognormal distribution,正态随机数的生成
- 截断正态分布(truncated normal distribution)
- Rotate Image
- ubuntu下sed命令详解
- java基础
- HDU 1429 BFS + 状压
- android中的线程执行UI更新方式,以及Handler的初步了解
- C++生成随机数:高斯/正态分布(gaussian/normal distribution)
- this指针
- Code Forces 59A Word
- 回调函数的原理及PHP实例
- redis sort命令用法
- 浮点数的输入以及浮点数运算
- UVa 401 - Palindromes
- 2015/8/16
- 107Binary Tree Level Order Traversal II