当前位置:网站首页>Generate random numbers with high quality and Gaussian distribution
Generate random numbers with high quality and Gaussian distribution
2022-04-23 16:53:00 【Tassel 1990】
Generate random numbers with high quality and Gaussian distribution
1、C# edition
1.1、 Use the following code ( Use MathNet.Numerics)
double[] createRandom(double mean, double stdDev, int sumCount)
{
Random rand = new Random();
MathNet.Numerics.Distributions.Normal normalDist = new Normal(mean, stdDev);
List<double> resultList = new List<double>();
for (int index = 0; index < sumCount; index++)
resultList.Add(normalDist.Sample());
return resultList.ToArray();
}
1.2、 For customized implementation, see (https://www.itranslater.com/qa/details/2325740528148677632)
Random rand = new Random(); //reuse this if you are generating many
double u1 = 1.0-rand.NextDouble(); //uniform(0,1] random doubles
double u2 = 1.0-rand.NextDouble();
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
double randNormal = mean + stdDev * randStdNormal; //random normal(mean,stdDev^2)
2、C++ edition
2.1、 Use boost_1_75_0 library
boost::normal_distribution<> nd(dAverage, dVariance);
版权声明
本文为[Tassel 1990]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231359253804.html
边栏推荐
猜你喜欢
PyMySQL
RTKLIB 2.4.3源码笔记
oracle 中快速获取表的列名列表
Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
OMNeT学习之新建工程
How much do you know about the process of the interview
详解牛客----手套
Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
STM32__03—初识定时器
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
随机推荐
Cartoon: what are IAAs, PAAS, SaaS?
Construction of promtail + Loki + grafana log monitoring system
Bytevcharts visual chart library, I have everything you want
Camtasia2022软件新增功能介绍
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
On the security of key passing and digital signature
PHP efficiently reads large files and processes data
Loggie source code analysis source file module backbone analysis
人脸识别框架之dlib
Encapsulating the logging module
LVM与磁盘配额
计组 | 【七 输入/输出系统】知识点与例题
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
Smart doc + Torna generate interface document
∑GL-透视投影矩阵的推导
Use case labeling mechanism of robot framework
Detailed explanation of file operation (2)
批量制造测试数据的思路,附源码
Log4j output log information to file