Board logo

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

作者: tonyh    時間: 2013-8-3 15:09     標題: 亂數 - 種子亂數

  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. }
複製代碼

作者: 張瀚仁    時間: 2013-8-3 15:10

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     scrand(5);
  7.     for(int i=1; i<=10;i++)
  8.     {         
  9.          cout<<rand()<<endl;         
  10.     }   
  11.     system("pause");   
  12.     return 0;
  13. }
複製代碼

作者: 林以諾    時間: 2013-8-3 15:10

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(100);
  7.     for(int i=1; i<=100 ;i++)
  8.     {
  9.             cout<<rand()<<endl;
  10.             }
  11.     system("pause");
  12.     return 0;
  13.     }
複製代碼

作者: 劉泳鱔    時間: 2013-8-3 15:11

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(24);
  7.     for(int i=1; i<=100; i++)
  8.     {
  9.          cout<<rand()<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 蘇昱安    時間: 2013-8-3 15:11

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(5);
  7.     for(int i=1; i<=100; i++)
  8.     {
  9.             
  10.          cout<<rand()<<endl;
  11.     }
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

作者: 黃崇維    時間: 2013-8-3 15:11

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(15);
  7.     for(int i=1; i<=100; i++)
  8.     {
  9.          cout<<rand()<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

作者: 鎧言    時間: 2013-8-3 15:11

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(24);
  7.     for(int i=1; i<=100; i++)
  8.     {
  9.          cout<<rand()<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 許逸群    時間: 2013-8-3 15:12

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(100);
  7.     for(int i=1; i<=100 ;i++)
  8.     {
  9.             cout<<rand()<<endl;
  10.             }
  11.     system("pause");
  12.     return 0;
  13.     }
複製代碼

作者: 郭凡瑛    時間: 2013-8-3 15:14

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(5);
  7.    for(int i=1; i<=100; i++)   
  8.     {
  9.      cout<<rand()<<endl;
  10.     }   
  11.     system("pause");
  12.     return 0;
  13.     }
複製代碼

作者: 黃柏維    時間: 2013-8-10 15:35

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(5);
  7.     for(int i=1; i<=10; i++)
  8.     {
  9.         cout<<rand()<<endl;
  10.     }
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

作者: 鎧言    時間: 2013-10-5 16:01

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int a=0;
  8.     while(a!=20)
  9.     {   
  10.         cout<<rand(a%4+1)<<endl;
  11.         a++;
  12.     }
  13.     system("pause");   
  14.     return 0;
  15. }
複製代碼





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