我想在不使用提升和“奇怪”的东西的情况下做到这一点,我想为生活游戏随机填充一个棋盘。
最佳答案
C++11 并用下面的代码来做
#include <random>
#include <vector>
int main()
{
std::mt19937 gen;
std::bernoulli_distribution dist;
std::vector<bool> bv;
bv.reserve(100);
for(unsigned i=0; i!=100; ++i)
bv.push_back( dist(gen));
return 0;
}
此外,我真的不明白对于 bool 来说,均匀分布和正态分布之间有什么区别。
请参阅此处了解 C++ 随机数。 http://en.cppreference.com/w/cpp/numeric/random
关于c++ - 如何在 C++ 中使用正态分布生成真值或假值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9447177/