惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 光光GG

最小生成树:使用堆和并查集的kruskal算法 最小生成树prim算法模板 【转】详细解说STL hash_map系列 松弛操作 SPFA算法 bellman-ford(贝尔曼-福特)算法 详细解说 STL 排序(Sort) c++常用算法收集 骨牌覆盖的已有研究 【转】自定义排序函数实现时需要注意的问题 【转】计算C++程序运行时间 【原】八数码问题(8-puzzle Problem) 解决netbeans乱码问题 在ubuntu8.04 stl vector 技巧 ACM中的64位整数 pku-1095-Trees Made to Order 七种qsort排序方法 memset ,memcpy sql server 通过mdf文件恢复数据库
产生满足正态分布的随机数
光光GG · 2008-07-17 · via 博客园 - 光光GG

一般有两种算法:  
  算法一产生12个(0,1)平均分布的随机函数,用大数定理可以模拟出正态分布。  
  算法二用到了数学中的雅可比变换,直接生成正态分布,但此算法在计算很大规模的数时 会出现溢出错误。
附加代码:

  #include   <math.h>  
  #include   
<stdio.h>  
  #include   
<conio.h>  
  #include   
<stdlib.h>  
  #include   
<time.h>  

  
#define M_PI 3.14159265358979323846

  
double   _random(void)  
  
{  
    
int   a;  
    
double   r;  
   
    a
=rand()%32767;  
    r
=(a+0.00)/32767.00;  
   
    
return   r;  
   
  }
  
   
  
double   _sta(double   mu,double   sigma)  
  
{  
    
int   i;  
    
double   r,sum=0.0;  
   
    
if(sigma<=0.0)   {   printf("Sigma<=0.0   in   _sta!");   exit(1);   }  
    
for(i=1;i<=12;i++)  
    sum   
=   sum   +   _random();  
    r
=(sum-6.00)*sigma+mu;  
   
    
return   r;  
   
  }
  
   
  
double   _sta2(double   mu,double   sigma)  
  
{  
    
double   r1,r2;  
   
    r1
=_random();  
    r2
=_random();  
   
    
return   sqrt(-2*log(r1))*cos(2*M_PI*r2)*sigma+mu   ;  
   
  }
  
   
   
  
int   main()  
  
{  
  
int   i;  
  
double   mu,sigma;  
   
  srand(   (unsigned)time(   NULL   )   );  
  mu
=0.0;  
  sigma
=1.0;  
  printf(
"Algorithm   1:\n");  
  
for(i=0;i<10;i++)  
  printf(
"%lf\t",_sta(mu,sigma));  
  printf(
"Algorithm   2:\n");  
  
for(i=0;i<10;i++)  
  printf(
"%lf\t",_sta2(mu,sigma));  
  
return   0;  
   
  }