当前位置:网站首页>How to generate random numbers with standard distribution or Gaussian distribution
How to generate random numbers with standard distribution or Gaussian distribution
2022-07-27 19:05:00 【bamboogz99】
#include <stdlib.h>
#include <math.h>
double gaussrand()
{
static double V1, V2, S;
static int phase = 0;
double X;
if(phase == 0) {
do {
double U1 = (double)rand() / RAND_MAX;
double U2 = (double)rand() / RAND_MAX;
V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while(S >= 1 || S == 0);
X = V1 * sqrt(-2 * log(S) / S);
} else
X = V2 * sqrt(-2 * log(S) / S);
phase = 1 - phase;
return X;
}The above code is based on Box-Muller Method , The basic idea is to generate two groups of independent random numbers U and V, These two groups of numbers are in (0,1] Evenly distributed , use U and V Generate two sets of independent standard normal distribution random variables X and Y:
.
边栏推荐
- WinForm screenshot save C code
- C file and folder input / output stream code
- Kinect for Unity3d----KinectManager
- JDBC-MySql 01 JDBC操作MySql(增删改查)
- Netred RGB mirror light touch chip-dlt8s15b-jericho
- Using functions to extract numbers from text strings in Excel
- MySQL 06 transaction, view, index, backup and recovery
- Leetcode first day of question brushing
- 转行软测&跳槽到新公司,工作怎样快速上手?
- Led with fan eye protection learning table lamp touch chip-dlt8s12a
猜你喜欢

USB rechargeable hand warmer chip dltap602sc Jericho

Unity learning notes (rigid body physics collider trigger)

Unity学习笔记(刚体-物理-碰撞器-触发器)

Big enemies, how to correctly choose the intended enterprises in the new testing industry?

Interviewer: what do you think is your biggest weakness?

JMeter interface automation - how to solve the content type conflict of request headers

Here are all the MySQL interview questions you can't expect (the latest version of 2022)

TypeScript安装

Household mute mosquito repellent lamp chip-dltap703sd-jericho

CMD 命令
随机推荐
Some advice for NS2 beginner.
JDBC-MySql 01 JDBC操作MySql(增删改查)
Resource for NS2 beginner
Leetcode brushes questions the next day
JMeter interface automation - how to solve the content type conflict of request headers
怎样产生标准分布或高斯分布的随机数
WPS turns off annoying advertisements
Useful resources for ns2
Nodejs template engine EJS
Using functions to extract numbers from text strings in Excel
SQL server stored procedures multi angle introduction suggestions collection
"Testing novice encyclopedia" 5-minute quick start pytest automated testing framework
Latex使用--subfigure竖排图形
IDEA成功连接Database但不显示表怎么办
TypeScript安装
MySQL 04 高级查询(二)
微机原理学习笔记-常见寻址方式
WinForm remove the close button in the upper right corner
npm 基本使用
Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
