Board logo

標題: 亂數 - 種子亂數 [打印本頁]

作者: 方浩葦    時間: 2024-6-22 03:13     標題: 亂數 - 種子亂數

先設定亂數種子,再利用 rand() 函式產生20組種子亂數。
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(5);
  7.     for(int i=1; i<=20; i++)
  8.         cout<<rand()<<endl;
  9.     system("pause");   
  10.     return 0;
  11. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2