当前位置:网站首页>怎样产生标准分布或高斯分布的随机数
怎样产生标准分布或高斯分布的随机数
2022-07-27 16:21: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;
}以上代码是基于Box-Muller方法,基本思想是生成两组独立的随机数U和V,这两组数在(0,1]上均匀分布,用U和V生成两组独立的标准常态分布随机变量X和Y:
。
边栏推荐
- Whole body multifunctional massage instrument chip-dltap602sd
- 你想得到想不到的MySQL面试题都在这了(2022最新版)
- Multifunctional wireless remote control moxibustion instrument chip dltap703sd
- MySQL 05 stored procedure
- Jianmu continuous integration platform v2.5.2 release
- Here are all the MySQL interview questions you can't expect (the latest version of 2022)
- Ruiji takeout notes
- Blog Garden beautification tutorial
- 模仿线程扣除
- Arrays and objects in JS
猜你喜欢

JS to realize simple form verification and select all functions

我人都傻了,CompletableFuture和OpenFegin一起使用竟然报错

Examples of map search
![[NPM] the](/img/ae/efccefae0323a1f6a425523e01d2ac.png)
[NPM] the "NPM" item cannot be recognized as the name of cmdlets, functions, script files or runnable programs. Please check the spelling of the name. If the path is included, make sure the path is co

Blog Garden beautification tutorial

低噪负离子风扇触摸IC

MySQL 02 初体验

JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)

面试官:你觉得你最大的缺点是什么?

Day 3 of leetcode question brushing
随机推荐
你想得到想不到的MySQL面试题都在这了(2022最新版)
Order submission
Interceptor拦截器
MySQL 04 advanced query (II)
Matplotlib(基本用法)
TypeError: conv2d(): argument ‘padding‘ (position 5) must be tuple of ints, not str【报错】
Zhaoqi scientific and technological innovation introduces high-level talents at home and abroad and connects innovation and entrepreneurship projects
Openstack login dashboard prompt authentication error
V-bind and V-for
Low noise anion fan touch IC
全身多功能按摩仪芯片-DLTAP602SD
JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)
订单超时取消 及 按类别查询商品
Day 3 of leetcode question brushing
MySQL 03 advanced query (I)
Imitation thread deduction
Matplotlib (basic usage)
JS to realize simple form verification and select all functions
LED学习护眼台灯触摸芯片-DLT8T10S-杰力科创
Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
