随机化


一般随机化


srand(time(0));
x = rand();

[a , b) : x = rand() % (b - a) + a;
[a , b] : x = rand() % (b - a + 1) + a;
(a , b] : x = rand() % (b - a) + (a + 1);
(0 , 1] : x = rand() / double(RAND_MAX);




伪随机生成器 mt19937

mt19937 rnd(time(nullptr)); // 生成 uint32 
mt19937_64 rnd(time(nullptr)); //生成 uint64
auto x = rnd();

//更强的随机种子
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
auto x = rnd();

posted @ 2023-05-30 15:42  xqy2003  阅读(19)  评论(0)    收藏  举报