-3
我正在尝试在main()函数中使用std :: uniform_real_distribution。在主我打电话进一步上在主函数中使用std :: uniform_real_distribution
unsigned seed =
std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine generator (seed);
std::uniform_real_distribution<double> distribution(0.0,1.0);
:
我播种发生器在main()如下
double number = distribution(generator)
当我需要的随机数。
问题是,我还需要(数百万) 随机数的函数。
想象我在调用一个函数main():
int main(){
void function(){
number = distribution(generator)
}
return 0;
}
如何做到这一点?如何在函数中“访问”随机数生成器。
非常感谢!
你把它传递给函数? – NathanOliver
不要使用时间作为种子,这不是随机的。不要使用'std :: default_random_engine',这通常是不好的([示例](https://stackoverflow.com/q/21843172/3002139))。你可以在我的问题[https://codereview.stackexchange.com/q/109260/47293]中找到一种方法来正确地播种一个好的RNG。 –