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

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

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

      • <bdo id='j4bhW'></bdo><ul id='j4bhW'></ul>
    2. <legend id='j4bhW'><style id='j4bhW'><dir id='j4bhW'><q id='j4bhW'></q></dir></style></legend>

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

        rand() 和 random() 函數(shù)有什么區(qū)別?

        What difference between rand() and random() functions?(rand() 和 random() 函數(shù)有什么區(qū)別?)
      1. <legend id='DQTXI'><style id='DQTXI'><dir id='DQTXI'><q id='DQTXI'></q></dir></style></legend>

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

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

                <tbody id='DQTXI'></tbody>

                  <bdo id='DQTXI'></bdo><ul id='DQTXI'></ul>
                  本文介紹了rand() 和 random() 函數(shù)有什么區(qū)別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  有一次,我的老師教我使用 randomize()random() 函數(shù)在 C++ Builder 中生成偽隨機數(shù).現(xiàn)在我更喜歡在 VS 2012 中工作,但是當我嘗試在 VS 2012 中使用這些函數(shù)時,即使我添加了 #include ,它也會顯示未找到標識符".經(jīng)過一段時間的谷歌搜索,我發(fā)現(xiàn)還有 rand()srand() 函數(shù).它們有什么區(qū)別,哪個更好用?

                  Once, my teacher taught me to use randomize() and random() function for generating pseudorandom numbers in C++ Builder. Now I prefer working in VS 2012, but when I tried to use these functions there it says that "identifier not found", even when I added #include <stdlib.h>. After some time of Googling I found that there are also rand() and srand() functions. What is the difference between them and which is it better to use?

                  推薦答案

                  randomize()random() 不是標準庫的一部分.也許您的老師用這些名稱編寫了用于您班級的函數(shù),或者您的意思可能是 random()srandom(),它們是 POSIX 的一部分,在 Windows 上不可用.rand()srand() 是標準庫的一部分,將由任何符合標準的 C++ 實現(xiàn)提供.

                  randomize() and random() are not part of the standard library. Perhaps your teacher wrote functions with these names for use in your class, or maybe you really mean random() and srandom() which are part of POSIX and not available on Windows. rand() and srand() are part of the standard library and will be provided by any standard conforming implementation of C++.

                  您應該避免使用 rand()srand() 并使用新的 C++11 庫. 是作為 C++11 標準的一部分添加的(VS2012 確實提供了它).

                  You should avoid rand() and srand() and use the new C++11 <random> library. <random> was added as part of the C++11 standard (and VS2012 does provide it).

                  解釋原因的視頻:rand()認為有害

                  Video explaining why: rand() Considered Harmful

                  • rand() 通常是低質(zhì)量的 pRNG,不適合需要合理水平不可預測性的應用程序. 提供了各種具有不同特性的引擎,適用于許多不同的用例.

                  • rand() is typically a low quality pRNG and not suitable for applications that need a reasonable level of unpredictability. <random> provides a variety of engines with different characteristics suitable for many different use cases.

                  rand()的結(jié)果轉(zhuǎn)化為可以直接使用的數(shù)字,通常依賴于難讀易出錯的代碼,而使用; 分發(fā)很容易并且產(chǎn)生可讀的代碼.

                  Converting the results of rand() into a number you can use directly usually relies on code that is difficult to read and easy to get wrong, whereas using <random> distributions is easy and produces readable code.

                  使用 rand() 在給定分布中生成值的常用方法進一步降低了生成數(shù)據(jù)的質(zhì)量.% 通常會使數(shù)據(jù)產(chǎn)生偏差,浮點除法仍然會產(chǎn)生非均勻分布. 分布質(zhì)量更高,可讀性更強.

                  The common methods of generating values in a given distribution using rand() further decrease the quality of the generated data. % generally biases the data and floating point division still produces non-uniform distributions. <random> distributions are higher quality as well as more readable.

                  rand() 依賴于一個隱藏的全局資源.除其他問題外,這會導致 rand() 不是線程安全的.一些實現(xiàn)可以保證線程安全,但這不是必需的標準.<random> 提供的引擎將 pRNG 狀態(tài)封裝為具有值語義的對象,允許對狀態(tài)進行靈活控制.

                  rand() relies on a hidden global resource. Among other issues this causes rand() to not be thread safe. Some implementations make thread safety guarantees, but this is not required standard. Engines provided by <random> encapsulate pRNG state as objects with value semantics, allowing flexible control over the state.

                  srand() 只允許有限范圍的種子. 中的引擎可以使用允許最大可能種子數(shù)據(jù)的種子序列進行初始化.seed_seq 還實現(xiàn)了一個常見的 pRNG 預熱.

                  srand() only permits a limited range of seeds. Engines in <random> can be initialized using seed sequences which permit the maximum possible seed data. seed_seq also implements a common pRNG warm-up.

                  使用的例子:

                  #include <iostream>
                  #include <random>
                  
                  int main() {
                    // create source of randomness, and initialize it with non-deterministic seed
                    std::random_device r;
                    std::seed_seq seed{r(), r(), r(), r(), r(), r(), r(), r()};
                    std::mt19937 eng{seed};
                  
                    // a distribution that takes randomness and produces values in specified range
                    std::uniform_int_distribution<> dist(1,6);
                  
                    for (int i=0; i<100; ++i) {
                      std::cout << dist(eng) << '
                  ';
                    }
                  }
                  

                  這篇關于rand() 和 random() 函數(shù)有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(liá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 類比是什么?)

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

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

                            <legend id='bEcL1'><style id='bEcL1'><dir id='bEcL1'><q id='bEcL1'></q></dir></style></legend>
                            主站蜘蛛池模板: 亚洲欧美在线一区 | 中文字幕精品视频在线观看 | 曰韩一二三区 | 秋霞a级毛片在线看 | 免费观看成人性生生活片 | 久久在线| 日韩欧美中文字幕在线观看 | 久久天堂| 精品美女在线观看视频在线观看 | a国产视频 | 色综合九九 | 精品免费av | 精品久久久久一区 | 中文字幕av免费 | 国产精品欧美一区二区 | 欧美一级片在线观看 | 久久久久久免费毛片精品 | 日本福利在线 | 成人在线视频网站 | 免费一区 | av日韩在线播放 | 91在线最新 | 精品久久久久久久久久 | 国产精品综合色区在线观看 | 69av在线视频 | 亚洲欧洲精品一区 | 日韩毛片在线视频 | 欧美一区二区三区在线观看 | 91在线免费观看网站 | 亚洲欧美日韩在线不卡 | 久久精品欧美一区二区三区不卡 | 精品美女 | 精品亚洲一区二区三区四区五区 | 一区精品视频 | 亚洲精品乱码久久久久久蜜桃91 | 伦理午夜电影免费观看 | 人人射人人 | 紧缚调教一区二区三区视频 | 亚洲欧美日韩中文在线 | 午夜av成人| 最近中文字幕第一页 |