当前位置:网站首页>【C语言】如何产生正态分布或高斯分布随机数
【C语言】如何产生正态分布或高斯分布随机数
2022-06-28 11:36:00 【贾璞】
使用中心极限定理(大数定理)将几个平均分布随机数加起来,从而产生正态分布或高斯分布随机数(有缺点)。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NSUM 23
double GaussRand()
{
double x = 0;
int i;
for (size_t i = 0; i < NSUM; i++)
{
x += (double)rand() / RAND_MAX;
x -= NSUM / 2.0;
x /= sqrt(NSUM / 12.0);
return x;
}
}
int main()
{
printf("%lf", GaussRand());
return 0;
}

这种方法实现起来虽然简单,但还是比较差的,尤其是当NSUM数值很小的时候。也有其他实现方法,下次再说。
边栏推荐
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration
- AGCO AI frontier promotion (2.16)
- 分析list中有无重复数据且重复了几次
- Convert black mask picture to color annotation file
- Research on personalized product search
- [sciter]: use of sciter FS module scanning file API and its details
- Redis 原理 - List
- 如临现场的视觉感染力,NBA决赛直播还能这样看?
猜你喜欢

Industry analysis - quick intercom, building intercom

Fruit FL studio/cubase/studio one music host software comparison

js中的数组方法 2021.09.18

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性

Share the easy-to-use fastadmin open source system - practical part

day32 js笔记 事件(上)2021.09.27

If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience

js中this的默认指向及如何修改指向 2021.11.09

Ali three sides: what is the difference between using on or where in the left join associated table and the condition

New listing of operation light 3.0 - a sincere work of self subversion across the times!
随机推荐
无法重新声明块范围变量
Day28 strict mode, string JS 2021.09.22
Machine learning project captcha based on verification code recognition_ Trainer operation practice
How to deploy the software testing environment?
Day34 JS notes regular expression 2021.09.29
Still using simpledateformat for time formatting? Be careful that the project collapses!
Solutions to connection failures and errors when accessing mysql8 using the SSM project
Redis hash hash type string (5)
setInterval、setTimeout和requestAnimationFrame
Convert black mask picture to color annotation file
建立自己的网站(18)
Open3d manual clipping point cloud
Simulation of the Saier lottery to seek expectation
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
Research on personalized product search
智联招聘基于 Nebula Graph 的推荐实践分享
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
3. seat number
太阳能无线LED显示屏的特点
AcWing 605. Simple product (implemented in C language)