gauss.c

来自「speech signal process tools」· C语言 代码 · 共 41 行

C
41
字号
/*| This material contains proprietary software of Entropic Processing, Inc.| Any reproduction, distribution, or publication without the the prior| written permission of Entropic Processing, Inc. is strictly prohibited.| Any public distribution of copies of this work authorized in writing by| Entropic Processing, Inc. must bear the notice||              "Copyright 1986 Entropic Processing, Inc."|| Written by:  S. Shankar Narayan|| Module:	gauss.c| */#ifdef SCCSstatic char *sccs_id = "@(#)gauss.c	1.2 4/21/86 (gauss.c)";#endiffloat gauss(dummy) /* gaussian random number generation */float dummy;{	extern float rand();	double sqrt(),log();	static int flag = 1;	double s,v1,v2;	static double x1,x2;	if (flag == 2) { flag = 1; return(x1);}	do 	    {	     v1 = 2.0*rand(dummy);	     v2 = 2.0*rand(dummy);	     s = v1*v1+v2*v2;	    }	while (s > 1.0);	x1 = sqrt(-2.0*log(s)/s);	x2 = v2*x1;	x1 = v1*x1;	flag = 2;	return (x2);}

⌨️ 快捷键说明

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