gauss.c

来自「内核中关于nano计时的功能」· C语言 代码 · 共 22 行

C
22
字号
/* * Generate a random number plucked from a Gaussian distribution with * mean zero and specified standard deviation. Needs cos(), log(), * rand48(), sqrt() from math library. */#include <stdlib.h>#include <math.h>double gauss(	double sigma		/* standard deviation */	){	double q1, q2;		/* double temps */	while ((q1 = drand48()) == 0);	q2 = drand48();/*printf("sigma %10.5lf q1 %10.5lf q2 %10.5lf\n", sigma, q1, q2);*/	return (sigma * sqrt(-2 * log(q1)) * cos(2 * M_PI * q2));}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?