当前位置:网站首页>【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数值很小的时候。也有其他实现方法,下次再说。
边栏推荐
- Database Series: is there any way to seamlessly upgrade the business tables of the database
- Convert black mask picture to color annotation file
- Apache2 configuration denies access to the directory, but can access the settings of the files inside
- .NET混合开发解决方案24 WebView2对比CefSharp的超强优势
- Unity screenshot function
- js中的数组方法 2021.09.18
- MapReduce项目案例3——温度统计
- Setinterval, setTimeout and requestanimationframe
- Day30 JS notes BOM and DOM 2021.09.24
- Solutions to connection failures and errors when accessing mysql8 using the SSM project
猜你喜欢

What method is required for word, PDF and txt files to realize full-text content retrieval?

Class pattern and syntax in JS 2021.11.10

day31 js笔记 DOM下 2021.09.26

Day36 JS notes ecma6 syntax 2021.10.09

Industry analysis - quick intercom, building intercom

Deployment and optimization of vsftpd service

QML控件类型:TabBar

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

Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧

赛尔号抽奖模拟求期望
随机推荐
Is it safe to buy stocks and open an account on the account QR code of the CICC securities manager? Ask the great God for help
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush
Using soapUI to obtain freemaker's FTL file template
一套十万级TPS的IM综合消息系统的架构实践与思考
3. seat number
Contract quantification system development (construction explanation) - contract quantification system development (source code analysis and ready-made cases)
Day24 JS notes 2021.09.15
智联招聘基于 Nebula Graph 的推荐实践分享
Apache2配置对目录拒绝访问,但是可以访问里面文件的设置
Interview skills for interview steps
Industry analysis - quick intercom, building intercom
Redis hash hash type string (5)
Mutual conversion between mytipartfile and file
Packaging and publishing application of jetpack compose desktop version
QML控件类型:TabBar
mysql-. SQL file phishing Online
人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了
[sciter]: how sciter uses i18 to realize multi language switching of desktop applications and its advantages and disadvantages
Cohere, a large model company, completed the round B financing of US $125million
Array method in JS 2021.09.18