今天学习了C++ 生成随机数 ,记录心得
#include<ctime> //调用包含时间库来作为类uuid
//随机数种子
srand((unsigned int)time(NULL));
int num = rand()%41 + 60; // 生成60到100
/*
*因为 rand() 函数会生成随机数
* rand()%40 对40取模会生成 0~39的随机数
*对41取模则生成 0~40
*再加60 则会得到我们想要的60~100
*/
对N取模得到 0 ~ (N-1)