返回列表 發帖

亂數 - 種子亂數

先設定亂數種子, 再利用 rand() 函式產生20組種子亂數
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     // 38 41 45 48 51 54 58
  7.    srand(8);
  8.    for(int i=0;i<20;i++)
  9.    {
  10.     // 2147483647
  11.    
  12.      cout << rand() << endl;        
  13.    }   
  14.    
  15.     system("pause");
  16.     return 0;
  17.    
  18. }
複製代碼

返回列表