当前位置:网站首页>[C language] how to generate normal or Gaussian random numbers
[C language] how to generate normal or Gaussian random numbers
2022-06-28 14:49:00 【Jia Pu】
Using the central limit theorem ( The law ) Add up several evenly distributed random numbers , Thus, normal distribution or Gaussian distribution random number is generated ( Have shortcomings ).
#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;
}

This method is simple to implement , But it's still bad , Especially when NSUM When the value is very small . There are other ways to do this , Next time .
边栏推荐
- Could you tell me whether the batch addition of Oracle such as insert all was not blocked?
- Seata数据库中出现以下问题要怎么解决呀?
- 机器人的运动范围(DFS)
- 智联招聘基于 Nebula Graph 的推荐实践分享
- The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)
- 2022下半年软考考试时间安排已确定!
- 2022年最新PyCharm激活破解码永久_详细安装教程(适用多版本)
- 加油站(贪心)
- Does Frankfurt currently support SQL?
- 【mysql学习笔记24】索引设计原则
猜你喜欢

动力电池,是这样被“瓜分”的

Steve Jobs of the United States, died; China jobs, sold

dolphinscheduler2.X的安装(亲测有效)

Recommendation letter brain correspondent: if love is just a chemical reaction, can you still believe in love?

腾讯再遭大股东Prosus减持:后者还从京东套现37亿美元

Talking from the little nematode -- tracing the evolution of nervous system and starting life simulation

物联网低代码平台常用《组件介绍》

Tencent cloud international ECS has no network after logging in. How to troubleshoot?

【mysql学习笔记23】索引优化

Vscode writes markdown file and generates pdf
随机推荐
Send2vec tutorial
js 判断字符串为空或者不为空
Configuration file encryption (simple use of jasypt)
使用LamdbaUpdateWrapper的setSql作用及风险
组合总和-Leetcode
开闭原则
Leetcode(665)——非递减数列
腾讯再遭大股东Prosus减持:后者还从京东套现37亿美元
Ionq and Ge research confirmed that quantum computing has great potential in risk aggregation
Softing epGate PB系列网关-可将PROFIBUS总线集成到EtherNet/IP网络
股票开户优惠链接,我如何才能得到?手机开户是安全么?
Based on asp Net based document retrieval system
Only four breakthrough Lenovo smart Summer Palace in mainland China won the "IDC Asia Pacific Smart City Award in 2022"
2022年焊工(技师)考试题库模拟考试平台操作
dolphinscheduler2. Installation of X (valid for personal test)
3. caller service call - dapr
vector详解+题目
5000倍回报,南非报业投资腾讯赚了一个省
Functools: high order functions and operations on callable objects (continuous updating ing...)
法兰克福地区目前支持sql了吗?