返回列表 發帖

亂數 - 種子亂數

  1. //加入srand(參數)函式設定亂數種子
  2. #include<iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(5);  //設定亂數種子
  8.     for(int i=1; i<=10; i++)
  9.     {
  10.         cout<<rand()<<endl;  //依據亂數種子的值產生固定亂數
  11.     }
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

返回列表