当前位置:网站首页>[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 .
边栏推荐
- Validate palindrome string
- 美因基因港交所上市:市值43亿港元 IPO被市场忽略
- Unable to create process using 'd:\program file
- Leetcode(665)——非递减数列
- js 判断字符串为空或者不为空
- Which securities company is the largest and safest? How to open an account is the safest
- open3d里pointcloud和numpy数组之间的转化
- 2022年焊工(技师)考试题库模拟考试平台操作
- Gas station (greedy)
- Leetcode (406) - rebuild the queue based on height
猜你喜欢
随机推荐
Leetcode (167) -- sum of two numbers II - input ordered array
智联招聘基于 Nebula Graph 的推荐实践分享
腾讯再遭大股东Prosus减持:后者还从京东套现37亿美元
Who is the main body of the waiting insurance record? Record in the local network security, right?
法兰克福地区目前支持sql了吗?
优巨新材冲刺深交所:拟募资6.5亿 年营收3.33亿
Numbers that only appear once
Configuration file encryption (simple use of jasypt)
Tencent was underweight again by prosus, the major shareholder: the latter also cashed out $3.7 billion from JD
How does Seata server 1.5.0 support mysql8.0?
Could you tell me whether the batch addition of Oracle such as insert all was not blocked?
How to solve the following problems in the Seata database?
code snippet
After nearly 20 years of operation, the Mars probe software based on win 98 has been upgraded for the first time
技术弄潮儿
从小小线虫谈起——溯源神经系统进化,开启生命模拟
2022中式烹调师(高级)试题及在线模拟考试
Opening and closing principle
【mysql学习笔记24】索引设计原则
证券公司和银行哪个更安全 怎么办理开户最安全









