C++ normal distribution
Everyday, I feel like being extracted from the fucking world. When walking in the street, with my eyes stareing at the void, like a hideous waking dead, I cannot help thinking about my tragic near future. When I was a little kid, I thought politics or time, is just a matter of more sophiscated entity or nation. But when it comes to me, when the dirt of this fucking time landed on my sheer shoulder, I finally realized the fragility of a single human being when facing up with the torrent of TIME. COVID, PROCLAIM 10043, TRAVEL BAN. WHERE SHOULD MY DREAM GO?
--序
使用C++内置的random_device可实现normal distribution。
First of all, create random_device rd
std::random_device rd;
这是一个根据机器硬件类型产生真随机数的generator。
Secondly, create mt19937.
std::mt19937 gen(rd());
mt19937是一个19937bit的预定义随机数。
Last, create normal distribution.
std::normal_distribution<> d{0, 1};
0 is mean and 1 is stddev.
d(gen)
调用以上snippet即可获得正态分布中的一个随机数。