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即可獲得正態分布中的一個隨機數。
浙公網安備 33010602011771號