返回列表 發帖

亂數 - 種子亂數

先設定亂數種子, 再利用 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. }
複製代碼

本帖最後由 吳孟修 於 2019-3-16 13:56 編輯
  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.     {
  9.         cout<<rand()<<endl;        
  10.     }
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

TOP

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

TOP

本帖最後由 洪寬瀧 於 2019-3-16 13:56 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.      srand(87);
  7. for(int l=1;l<=20;l++)
  8. {
  9.   cout<<rand()<<endl;      
  10. }

  11.   system("pause");
  12.   return 0;

  13. }
複製代碼

TOP

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

TOP

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

TOP

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

TOP

  1. #include<iostream>          //☆★◇◆□■▽▼㊣℅¯>﹤㏒
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {                                                     //alt+41405=■,alt+41404=□;
  6. re:
  7.      for(int i=1; i<=65; i++)
  8.      {
  9.      if(i>=1 && i<=5)
  10.      cout<<"□□□□□□□□□□"<<endl;
  11.      if(i>=1 && i<=5)
  12.      cout<<"■□□□□□□□□□"<<endl;        
  13.      if(i>=1 && i<=5)
  14.      cout<<"■■□□□□□□□□"<<endl;  
  15.      if(i>=1 && i<=5)
  16.      cout<<"■■■□□□□□□□"<<endl;
  17.      if(i>=1 && i<=5)
  18.      cout<<"□■■■□□□□□□"<<endl;
  19.      if(i>=1 && i<=5)
  20.      cout<<"□□■■■□□□□□"<<endl;
  21.      if(i>=1 && i<=5)
  22.      cout<<"□□□■■■□□□□"<<endl;
  23.      if(i>=1 && i<=5)
  24.      cout<<"□□□□■■■□□□"<<endl;
  25.      if(i>=1 && i<=5)
  26.      cout<<"□□□□□■■■□□"<<endl;
  27.      if(i>=1 && i<=5)
  28.      cout<<"□□□□□□■■■□"<<endl;
  29.      if(i>=1 && i<=5)
  30.      cout<<"□□□□□□□■■■"<<endl;
  31.      if(i>=1 && i<=5)
  32.      cout<<"□□□□□□□□■■"<<endl;
  33.      if(i>=1 && i<=5)
  34.      cout<<"□□□□□□□□□■"<<endl;
  35.    
  36. }                                                   
  37. goto re;
  38.   system("pause");
  39. return 0;
  40. }   
複製代碼

TOP

返回列表