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

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - 光光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;  
   
  }