久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='gGhjb'><tr id='gGhjb'><dt id='gGhjb'><q id='gGhjb'><span id='gGhjb'><b id='gGhjb'><form id='gGhjb'><ins id='gGhjb'></ins><ul id='gGhjb'></ul><sub id='gGhjb'></sub></form><legend id='gGhjb'></legend><bdo id='gGhjb'><pre id='gGhjb'><center id='gGhjb'></center></pre></bdo></b><th id='gGhjb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gGhjb'><tfoot id='gGhjb'></tfoot><dl id='gGhjb'><fieldset id='gGhjb'></fieldset></dl></div>
      <bdo id='gGhjb'></bdo><ul id='gGhjb'></ul>

        <legend id='gGhjb'><style id='gGhjb'><dir id='gGhjb'><q id='gGhjb'></q></dir></style></legend>
      1. <small id='gGhjb'></small><noframes id='gGhjb'>

      2. <tfoot id='gGhjb'></tfoot>

        為什么 rand() 每次運行都會產生相同的數字序列

        Why does rand() yield the same sequence of numbers on every run?(為什么 rand() 每次運行都會產生相同的數字序列?)

          • <bdo id='3HmNd'></bdo><ul id='3HmNd'></ul>
            <tfoot id='3HmNd'></tfoot>

            <small id='3HmNd'></small><noframes id='3HmNd'>

            1. <legend id='3HmNd'><style id='3HmNd'><dir id='3HmNd'><q id='3HmNd'></q></dir></style></legend>
                <tbody id='3HmNd'></tbody>
              <i id='3HmNd'><tr id='3HmNd'><dt id='3HmNd'><q id='3HmNd'><span id='3HmNd'><b id='3HmNd'><form id='3HmNd'><ins id='3HmNd'></ins><ul id='3HmNd'></ul><sub id='3HmNd'></sub></form><legend id='3HmNd'></legend><bdo id='3HmNd'><pre id='3HmNd'><center id='3HmNd'></center></pre></bdo></b><th id='3HmNd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3HmNd'><tfoot id='3HmNd'></tfoot><dl id='3HmNd'><fieldset id='3HmNd'></fieldset></dl></div>
                • 本文介紹了為什么 rand() 每次運行都會產生相同的數字序列?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  每次我用 rand() 運行程序時,它都會給我相同的結果.

                  示例:

                  #include #include 使用命名空間標準;int隨機(int低,int高){如果(低>高)回報高;返回低 + (rand() % (高 - 低 + 1));}int main (int argc, char* argv []) {for (int i = 0; i <5; i++)cout<<隨機 (2, 5) <<結束;}

                  輸出:

                  35423

                  每次我運行程序時,它每次都會輸出相同的數字.有沒有辦法解決這個問題?

                  解決方案

                  未設置隨機數生成器的種子.

                  如果你調用 srand((unsigned int)time(NULL)) 那么你會得到更多的隨機結果:

                  #include #include #include <ctime>使用命名空間標準;int main() {srand((unsigned int)time(NULL));cout<<蘭特()<<結束;返回0;}

                  原因是從 rand() 函數生成的隨機數實際上并不是隨機的.這簡直就是一種轉變.維基百科對偽隨機數生成器的含義給出了更好的解釋:確定性隨機位生成器.每次調用 rand() 時,它都會獲取生成的種子和/或最后一個隨機數(C 標準沒有指定使用的算法,盡管 C++11 具有指定一些流行的算法),對這些數字運行數學運算,并返回結果.因此,如果種子狀態每次都相同(就像您不使用真正的隨機數調用 srand 一樣),那么您將始終得到相同的隨機"數.

                  如果您想了解更多,可以閱讀以下內容:

                  http://www.dreamincode.net/forums/topic/24225-random-number-generation-102/

                  http://www.dreamincode.net/forums/topic/29294-making-pseudo-random-number-generators-more-random/

                  Every time I run a program with rand() it gives me the same results.

                  Example:

                  #include <iostream>
                  #include <cstdlib>
                  
                  using namespace std;
                  
                  int random (int low, int high) {
                      if (low > high)
                          return high;
                      return low + (rand() % (high - low + 1));
                  }
                  
                  int main (int argc, char* argv []) {
                      for (int i = 0; i < 5; i++)
                          cout << random (2, 5) << endl;
                  }
                  

                  Output:

                  3
                  5
                  4
                  2
                  3
                  

                  Each time I run the program it outputs the same numbers every time. Is there a way around this?

                  解決方案

                  The seed for the random number generator is not set.

                  If you call srand((unsigned int)time(NULL)) then you will get more random results:

                  #include <iostream>
                  #include <cstdlib>
                  #include <ctime>
                  using namespace std;
                  
                  int main() {
                      srand((unsigned int)time(NULL));
                      cout << rand() << endl;
                      return 0;
                  }
                  

                  The reason is that a random number generated from the rand() function isn't actually random. It simply is a transformation. Wikipedia gives a better explanation of the meaning of pseudorandom number generator: deterministic random bit generator. Every time you call rand() it takes the seed and/or the last random number(s) generated (the C standard doesn't specify the algorithm used, though C++11 has facilities for specifying some popular algorithms), runs a mathematical operation on those numbers, and returns the result. So if the seed state is the same each time (as it is if you don't call srand with a truly random number), then you will always get the same 'random' numbers out.

                  If you want to know more, you can read the following:

                  http://www.dreamincode.net/forums/topic/24225-random-number-generation-102/

                  http://www.dreamincode.net/forums/topic/29294-making-pseudo-random-number-generators-more-random/

                  這篇關于為什么 rand() 每次運行都會產生相同的數字序列?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  read input files, fastest way possible?(讀取輸入文件,最快的方法?)
                  The easiest way to read formatted input in C++?(在 C++ 中讀取格式化輸入的最簡單方法?)
                  Reading from .txt file into two dimensional array in c++(從 .txt 文件讀取到 C++ 中的二維數組)
                  How to simulate a key press in C++(如何在 C++ 中模擬按鍵按下)
                  Why doesn#39;t getline(cin, var) after cin.ignore() read the first character of the string?(為什么在 cin.ignore() 之后沒有 getline(cin, var) 讀取字符串的第一個字符?)
                  What is the cin analougus of scanf formatted input?(scanf 格式輸入的 cin 類比是什么?)
                    <tbody id='HEGmj'></tbody>

                  <small id='HEGmj'></small><noframes id='HEGmj'>

                  <legend id='HEGmj'><style id='HEGmj'><dir id='HEGmj'><q id='HEGmj'></q></dir></style></legend>

                    • <tfoot id='HEGmj'></tfoot>

                          <bdo id='HEGmj'></bdo><ul id='HEGmj'></ul>
                          <i id='HEGmj'><tr id='HEGmj'><dt id='HEGmj'><q id='HEGmj'><span id='HEGmj'><b id='HEGmj'><form id='HEGmj'><ins id='HEGmj'></ins><ul id='HEGmj'></ul><sub id='HEGmj'></sub></form><legend id='HEGmj'></legend><bdo id='HEGmj'><pre id='HEGmj'><center id='HEGmj'></center></pre></bdo></b><th id='HEGmj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HEGmj'><tfoot id='HEGmj'></tfoot><dl id='HEGmj'><fieldset id='HEGmj'></fieldset></dl></div>
                            主站蜘蛛池模板: 日韩欧美手机在线 | 黄色精品视频网站 | 欧美激情视频网站 | 成人在线一区二区三区 | 日韩精品一区二区三区中文在线 | 精品乱人伦一区二区三区 | 青青久久av北条麻妃海外网 | 久久久久久久久综合 | 日日干日日操 | 久久精品毛片 | 午夜伦4480yy私人影院 | japanhdxxxx裸体| 久久精品中文字幕 | 国产午夜精品一区二区三区嫩草 | 国产a爽一区二区久久久 | 午夜久久久 | 九热在线 | 每日更新av | 久久久国产一区 | 欧美国产日韩在线观看 | www.黄色片视频 | 国产精品久久一区二区三区 | 午夜精品视频一区 | 污视频免费在线观看 | 真人女人一级毛片免费播放 | 国产成人艳妇aa视频在线 | 亚洲精品第一国产综合野 | 伊人精品久久久久77777 | 成人精品一区二区三区中文字幕 | 欧美精品一区二区在线观看 | 国产污视频在线 | 日本精品一区二区三区在线观看视频 | 在线一区 | 日韩人体在线 | 福利视频日韩 | 粉嫩一区二区三区四区公司1 | 欧美黄色性生活视频 | 日韩视频在线免费观看 | 精品国产91 | 99这里只有精品 | 51ⅴ精品国产91久久久久久 |