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

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

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

        <tfoot id='bjrHL'></tfoot>
      1. srand(time(NULL)) 產(chǎn)生類似的結(jié)果

        srand(time(NULL)) generating similar results(srand(time(NULL)) 產(chǎn)生類似的結(jié)果)
            <tbody id='TsmRk'></tbody>
          1. <legend id='TsmRk'><style id='TsmRk'><dir id='TsmRk'><q id='TsmRk'></q></dir></style></legend>
            <i id='TsmRk'><tr id='TsmRk'><dt id='TsmRk'><q id='TsmRk'><span id='TsmRk'><b id='TsmRk'><form id='TsmRk'><ins id='TsmRk'></ins><ul id='TsmRk'></ul><sub id='TsmRk'></sub></form><legend id='TsmRk'></legend><bdo id='TsmRk'><pre id='TsmRk'><center id='TsmRk'></center></pre></bdo></b><th id='TsmRk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TsmRk'><tfoot id='TsmRk'></tfoot><dl id='TsmRk'><fieldset id='TsmRk'></fieldset></dl></div>
              <bdo id='TsmRk'></bdo><ul id='TsmRk'></ul>

              • <small id='TsmRk'></small><noframes id='TsmRk'>

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

                  本文介紹了srand(time(NULL)) 產(chǎn)生類似的結(jié)果的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我不明白為什么 srand() 在運(yùn)行之間生成如此相似的隨機(jī)數(shù)

                  I don't understand why srand() generates so similar random numbers between runs!

                  我正在嘗試運(yùn)行以下代碼

                  I am trying to run the following code

                  srand ( time(NULL) );
                  int x = rand();
                  cout << x << endl;
                  

                  然而,我總是得到幾乎相同的數(shù)字,而不是一個(gè)正確的隨機(jī)數(shù),隨著時(shí)間的推移,這個(gè)數(shù)字增長(zhǎng)緩慢.所以我得到的數(shù)字是:11669、11685、11701、11714、11731.

                  However instead of a proper random number I always end up with almost the same number, which is growing slowly as the time goes. So I get numbers like: 11669, 11685, 11701, 11714, 11731.

                  我做錯(cuò)了什么?

                  我使用的是 Visual Studio 2010 SP1.

                  I am using Visual Studio 2010 SP1.

                  好吧,srand() 真的那么簡(jiǎn)單嗎?我的意思是怎么會(huì)有人稱它為隨機(jī)函數(shù)?

                  OK, is srand() really that simple? I mean how would anyone call it a random function?

                  srand(1) => rand() = 41
                  srand(2) => rand() = 45
                  srand(3) => rand() = 48
                  srand(4) => rand() = 51
                  ....
                  

                  推薦答案

                  一、srand() 不是隨機(jī)函數(shù);它設(shè)置了起點(diǎn)偽隨機(jī)序列.有點(diǎn)令人驚訝的是,你的rand() 的實(shí)現(xiàn)似乎是返回一個(gè)基于之前的狀態(tài),而不是新計(jì)算的狀態(tài),所以第一個(gè)調(diào)用 srand() 后的值在很大程度上取決于傳遞給的值srand().如果你要寫(xiě):

                  First, srand() isn't a random function; it sets up the starting point of a pseudo-random sequence. And somewhat surprisingly, your implementation of rand() seems to be returning a value based on the previous state, and not on the newly calculated state, so that the first value after a call to srand() depends very much on the value passed to srand(). If you were to write:

                  srand( time( NULL ) );
                  rand();
                  std::cout << rand() << std::endl;
                  

                  ,我相信你會(huì)看到更多的不同.

                  , I'm sure you'll see a lot more difference.

                  FWIW:我在 Windows 和 Linux 上都嘗試了以下方法:

                  FWIW: I tried the following on both Windows and Linux:

                  int
                  main()
                  {
                      srand( time( NULL ) );
                      int r1 = rand();
                      std::cout << r1 << ' ' << rand() << std::endl;
                      return 0;
                  }
                  

                  以一秒為間隔調(diào)用 10 次,我得到:

                  Invoked 10 times at a one second interval, I got:

                  16391 14979
                  16394 25727
                  16397 3708
                  16404 25205
                  16407 3185
                  16410 13933
                  16417 2662
                  16420 13411
                  16427 2139
                  

                  在 Windows 下使用 VC++—您會(huì)注意到第一次調(diào)用 rand()—and

                  with VC++ under Windows—you'll note the very low variance of the first call to rand()—and

                  1256800221 286343522
                  955907524 101665620
                  1731118607 991002476
                  1428701871 807009391
                  44395298 1688573463
                  817243457 1506183315
                  507034261 1310184381
                  1278902902 54648487
                  2049484769 942368151
                  1749966544 1833343137
                  

                  在Windows下使用g++;在這種情況下,即使讀取的第一個(gè)值也是相對(duì)隨機(jī).

                  with g++ under Windows; in this case, even the first value read is relatively random.

                  如果你需要一個(gè)好的隨機(jī)生成器,你可能不得不使用一個(gè)來(lái)自 Boost;該標(biāo)準(zhǔn)并沒(méi)有說(shuō)明什么算法應(yīng)該是使用,并且實(shí)現(xiàn)的質(zhì)量差異很大.

                  If you need a good random generator, you'll probably have to use one from Boost; the standard doesn't say much about what algorithm should be used, and implementations have varied enormously in quality.

                  這篇關(guān)于srand(time(NULL)) 產(chǎn)生類似的結(jié)果的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Why do two functions have the same address?(為什么兩個(gè)函數(shù)的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                  mixing templates with polymorphism(混合模板與多態(tài)性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫(kù))
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
                  <legend id='tqEke'><style id='tqEke'><dir id='tqEke'><q id='tqEke'></q></dir></style></legend>
                    1. <tfoot id='tqEke'></tfoot>

                    2. <small id='tqEke'></small><noframes id='tqEke'>

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

                            主站蜘蛛池模板: 久久激情视频 | 亚洲成人免费观看 | 国产精品乱码一区二三区小蝌蚪 | 一级做a爰片性色毛片16 | 99re在线 | 在线成人免费视频 | 99这里只有精品视频 | 国产乱码高清区二区三区在线 | 欧美性一区二区三区 | 激情91 | 中文字幕日韩一区 | 久久久国产一区二区三区 | 男女视频在线观看网站 | 欧美日韩中 | 欧美激情在线精品一区二区三区 | 国产一区二 | 日韩av在线免费 | 伊人在线 | 国产成人在线播放 | 亚洲国产欧美一区二区三区久久 | av网站在线播放 | 日韩精品一区二区久久 | 中文字幕一区二区三区在线观看 | 久久a久久 | 亚洲精品免费在线 | 国产农村妇女毛片精品久久麻豆 | 欧美一区 | 国产成人jvid在线播放 | 久久久久久国产 | 久久狠狠 | 99精品视频免费观看 | 欧洲视频一区二区 | 欧美成人免费在线视频 | 国产精品免费一区二区三区 | 精品亚洲一区二区 | 人人草天天草 | 久久久久久久久久一区 | 午夜视频在线免费观看 | 精品欧美乱码久久久久久1区2区 | 亚洲精品视频免费看 | 大象一区|