拉普拉斯c语言程序
double uniform(double a,double b,signed int seed)
{
double t;
seed=2045*seed+1;
seed=seed-(seed/1048576)*1048576;
t=(seed)/1048576.0;
t=a+(b-a)*t;
return(t);
}
/*******************************************************************
* 拉普拉斯随机分布
* beta--拉普拉斯分布的参数
* seed--随机数种子
*******************************************************************/
double laplace(double beta,signed int seed)
{
double u1,u2,x;
u1=uniform(0.,1.,seed);
u2=uniform(0.,1.,seed);
if(u1<=0.5)
x=-beta*log(1.-u2);
else
x=beta*log(u2);
return(x);
}