onetrainee

srand()与rand()生成随机数

经过测试,当srand的值确定时,其对应的rand值也是确定的。

 

#include <iostream>
using namespace std;
int main()
{
    for (int i = 0; i <= 10; i++) {
        srand(i);
        cout << "当seed = " << i << "时,其结果为:" << rand() << endl;
    }

    cout << endl << endl << "------第二次验证---------" << endl << endl;

    for (int i = 0; i <= 10; i++) {
        srand(i);
        cout << "当seed = " << i << "时,其结果为:" << rand() << endl;
    }
}

 

 

 

 

 

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2021-08-15
  • 2021-12-09
  • 2021-12-09
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2021-12-09
  • 2021-08-05
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-07-09
相关资源
相似解决方案