草庐IT

GetRandDoubleBetween0

全部标签

c++ - C++11 : is there a simple way to seed the generator in one place of the code, 中的随机数然后在不同的函数中使用它?

在C++11之前,我使用rand()来自选择在main()中播种(或不播种)生成器非常简单函数(例如),然后在libraryA中使用由libraryB中某个函数生成的随机数。代码如下所示:LibraryB(生成随机数,老式的方式):#include//rand,RAND_MAXdoubleGetRandDoubleBetween0And1(){return((double)rand())/((double)RAND_MAX);}主程序:#include//srand#include//time,clockintmain(){booliWantToSeed=true;//orfalse,