转自:http://www.cnblogs.com/yeahgis/archive/2012/07/13/2590485.html

高斯分布也称为正态分布(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; }

 

相关文章:

  • 2021-04-11
  • 2021-12-18
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-01-03
  • 2021-11-08
  • 2022-03-04
猜你喜欢
  • 2021-11-27
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
相关资源
相似解决方案