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

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

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

    <tfoot id='GVcaJ'></tfoot>

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

        • <bdo id='GVcaJ'></bdo><ul id='GVcaJ'></ul>

        rand() 生成相同的數(shù)字——即使在我的主要內(nèi)容中

        rand() generating the same number – even with srand(time(NULL)) in my main!(rand() 生成相同的數(shù)字——即使在我的主要內(nèi)容中有 srand(time(NULL)) !)
            <tbody id='vI2cn'></tbody>

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

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

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

                  <bdo id='vI2cn'></bdo><ul id='vI2cn'></ul>

                  <tfoot id='vI2cn'></tfoot>
                • 本文介紹了rand() 生成相同的數(shù)字——即使在我的主要內(nèi)容中有 srand(time(NULL)) !的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  所以,我正在嘗試創(chuàng)建一個隨機(jī)向量(想想幾何圖形,而不是一個可擴(kuò)展的數(shù)組),每次我調(diào)用隨機(jī)向量函數(shù)時,我都會得到相同的 x 值,盡管 y 和 z 不同.

                  So, I'm trying to create a random vector (think geometry, not an expandable array), and every time I call my random vector function I get the same x value, though y and z are different.

                  int main () {
                      srand ( (unsigned)time(NULL));
                      Vector<double> a;
                      a.randvec();
                      cout << a << endl;
                      return 0;
                  }
                  

                  使用函數(shù)

                  //random Vector
                  template <class T>
                  void Vector<T>::randvec()
                  {
                      const int min=-10, max=10;
                      int randx, randy, randz;
                  
                      const int bucket_size = RAND_MAX/(max-min);
                  
                      do randx = (rand()/bucket_size)+min;
                      while (randx <= min && randx >= max);
                      x = randx;
                  
                      do randy = (rand()/bucket_size)+min;
                      while (randy <= min && randy >= max);
                      y = randy;
                  
                      do randz = (rand()/bucket_size)+min;
                      while (randz <= min && randz >= max);
                      z = randz;
                  }
                  

                  出于某種原因,randx 將始終返回 8,而其他數(shù)字似乎完全遵循(偽)隨機(jī)性.但是,如果我在 randx 之前調(diào)用定義,比如蘭迪,蘭迪將始終返回 8.

                  For some reason, randx will consistently return 8, whereas the other numbers seem to be following the (pseudo) randomness perfectly. However, if I put the call to define, say, randy before randx, randy will always return 8.

                  為什么我的第一個隨機(jī)數(shù)總是 8?是我播種不正確嗎?

                  Why is my first random number always 8? Am I seeding incorrectly?

                  推薦答案

                  問題是隨機(jī)數(shù)生成器的種子值非常接近 - 程序的每次運(yùn)行只會改變時間的返回值() 少量 - 可能是 1 秒,甚至可能沒有!相當(dāng)差的標(biāo)準(zhǔn)隨機(jī)數(shù)生成器然后使用這些相似的種子值來生成明顯相同的初始隨機(jī)數(shù).基本上,您需要一個比 time() 更好的初始種子生成器和一個比 rand() 更好的隨機(jī)數(shù)生成器.

                  The issue is that the random number generator is being seeded with a values that are very close together - each run of the program only changes the return value of time() by a small amount - maybe 1 second, maybe even none! The rather poor standard random number generator then uses these similar seed values to generate apparently identical initial random numbers. Basically, you need a better initial seed generator than time() and a better random number generator than rand().

                  我認(rèn)為實(shí)際使用的循環(huán)算法是從 Accelerated C++ 中提取的,旨在在所需范圍內(nèi)產(chǎn)生更好的數(shù)字分布,而不是使用 mod 運(yùn)算符.但它無法彌補(bǔ)總是(有效地)給予相同的種子.

                  The actual looping algorithm used is I think lifted from Accelerated C++ and is intended to produce a better spread of numbers over the required range than say using the mod operator would. But it can't compensate for always being (effectively) given the same seed.

                  這篇關(guān)于rand() 生成相同的數(shù)字——即使在我的主要內(nèi)容中有 srand(time(NULL)) !的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  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++ 中的二維數(shù)組)
                  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 類比是什么?)

                • <legend id='kiW6c'><style id='kiW6c'><dir id='kiW6c'><q id='kiW6c'></q></dir></style></legend>
                  • <bdo id='kiW6c'></bdo><ul id='kiW6c'></ul>

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

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

                            主站蜘蛛池模板: 999国产视频 | 伊人影院在线观看 | 欧美精品在线看 | 伊人精品在线 | 国产一级在线 | 91久久| 成人免费大片黄在线播放 | 91 在线 | 欧美一区二区三区在线观看 | 国产精品国产a | 天堂亚洲 | 91xh98hx 在线 国产 | 亚洲男人的天堂网站 | 精品九九| 99成人在线视频 | 影音先锋中文字幕在线观看 | 精品不卡 | 亚洲精品一区在线观看 | 精品视频免费 | 97精品超碰一区二区三区 | 色呦呦网站 | 亚洲va在线va天堂va狼色在线 | 中文字幕高清免费日韩视频在线 | 一区二区三区 在线 | 黄色网毛片 | 亚洲一区二区三区四区在线观看 | 成人毛片视频在线播放 | 免费看片国产 | 亚洲精品在线视频 | 日日操视频 | 日本免费在线 | 国产精品视频免费观看 | 蜜桃视频在线观看免费视频网站www | 国产96在线 | 国产欧美一区二区三区日本久久久 | 蜜桃视频在线观看www社区 | 国产日韩欧美 | 色视频www在线播放国产人成 | 国产玖玖 | 国产精品久久久久久久久久 | 日韩在线视频观看 |