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

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

    2. <small id='33N9t'></small><noframes id='33N9t'>

      <legend id='33N9t'><style id='33N9t'><dir id='33N9t'><q id='33N9t'></q></dir></style></legend>
        • <bdo id='33N9t'></bdo><ul id='33N9t'></ul>
      1. <tfoot id='33N9t'></tfoot>

        為什么 rand() 的使用被認為是不好的?

        Why is the use of rand() considered bad?(為什么 rand() 的使用被認為是不好的?)
      2. <small id='1Zk0g'></small><noframes id='1Zk0g'>

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

            <bdo id='1Zk0g'></bdo><ul id='1Zk0g'></ul>
              • <legend id='1Zk0g'><style id='1Zk0g'><dir id='1Zk0g'><q id='1Zk0g'></q></dir></style></legend>
                  <tbody id='1Zk0g'></tbody>

                <tfoot id='1Zk0g'></tfoot>

                  本文介紹了為什么 rand() 的使用被認為是不好的?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  盡管通過 srand() 使用種子,但通常不贊成使用 rand().為什么會是這樣?有哪些更好的替代方案?

                  Usage of rand() is usually frowned upon despite using a seed via srand(). Why would that be the case? What better alternatives are available?

                  推薦答案

                  這個故事有兩個部分.

                  首先,rand 是一個偽隨機數(shù)生成器.這意味著它取決于種子.對于給定的種子,它總是給出相同的序列(假設(shè)實現(xiàn)相同).這使得它不適合某些安全性非常重要的應(yīng)用程序.但是這并不特定于rand.這是任何偽隨機生成器的問題.并且肯定有很多類別的問題可以接受偽隨機生成器.真隨機生成器有其自身的問題(效率、實現(xiàn)、熵),因此對于與安全無關(guān)的問題,通常使用偽隨機生成器.

                  First, rand is a pseudorandom number generator. This means it depends on a seed. For a given seed it will always give the same sequence (assuming the same implementation). This makes it not suitable for certain applications where security is of a great concern. But this is not specific to rand. It's an issue with any pseudo-random generator. And there are most certainly a lot of classes of problems where a pseudo-random generator is acceptable. A true random generator has its own issues (efficiency, implementation, entropy) so for problems that are not security related most often a pseudo-random generator is used.

                  所以您分析了您的問題并得出結(jié)論,偽隨機生成器是解決方案.在這里,我們遇到了 C 隨機庫(包括 randsrand)的真正麻煩,這些庫是特定于它的,并使其過時(又名:您應(yīng)該從不使用 rand 和 C 隨機庫的原因).

                  So you analyzed your problem and you conclude a pseudo-random generator is the solution. And here we arrive to the real troubles with the C random library (which includes rand and srand) that are specific to it and make it obsolete (a.k.a.: the reasons you should never use rand and the C random library).

                  • 一個問題是它有全局狀態(tài)(由srand設(shè)置).這使得無法同時使用多個隨機引擎.它還使多線程任務(wù)變得非常復(fù)雜.

                  • One issue is that it has a global state (set by srand). This makes it impossible to use multiple random engines at the same time. It also greatly complicates multithreaded tasks.

                  其中最明顯的問題是缺少分發(fā)引擎:rand 給你一個區(qū)間[0 RAND_MAX].在這個區(qū)間是一致的,也就是說這個區(qū)間的每個數(shù)字出現(xiàn)的概率都是一樣的.但大多數(shù)情況下,您需要一個特定時間間隔內(nèi)的隨機數(shù).假設(shè) [0, 1017].一個常用的(也很簡單的)公式是 rand() % 1018.但問題在于,除非 RAND_MAX1018 的精確倍數(shù),否則您不會得到均勻分布.

                  The most visible problem of it is that it lacks a distribution engine: rand gives you a number in interval [0 RAND_MAX]. It is uniform in this interval, which means that each number in this interval has the same probability to appear. But most often you need a random number in a specific interval. Let's say [0, 1017]. A commonly (and naive) used formula is rand() % 1018. But the issue with this is that unless RAND_MAX is an exact multiple of 1018 you won't get an uniform distribution.

                  另一個問題是rand 的實現(xiàn)質(zhì)量.這里還有其他答案比我更詳細地說明了這一點,所以請閱讀它們.

                  Another issue is the Quality of Implementation of rand. There are other answers here detailing this better than I could, so please read them.

                  在現(xiàn)代 C++ 中,您絕對應(yīng)該使用 <random> 中的 C++ 庫,它帶有多個定義良好的隨機引擎以及整數(shù)和浮點類型的各種分布.

                  In modern C++ you should definitely use the C++ library from <random> which comes with multiple random well-defined engines and various distributions for integer and floating point types.

                  這篇關(guān)于為什么 rand() 的使用被認為是不好的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 類比是什么?)
                  • <tfoot id='buACH'></tfoot>
                      <tbody id='buACH'></tbody>

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

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

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

                          1. <i id='buACH'><tr id='buACH'><dt id='buACH'><q id='buACH'><span id='buACH'><b id='buACH'><form id='buACH'><ins id='buACH'></ins><ul id='buACH'></ul><sub id='buACH'></sub></form><legend id='buACH'></legend><bdo id='buACH'><pre id='buACH'><center id='buACH'></center></pre></bdo></b><th id='buACH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='buACH'><tfoot id='buACH'></tfoot><dl id='buACH'><fieldset id='buACH'></fieldset></dl></div>
                            主站蜘蛛池模板: 亚洲高清在线观看 | 午夜国产羞羞视频免费网站 | 国产日韩欧美在线 | 久久久91精品国产一区二区三区 | 欧美一级大片免费观看 | 日韩精品视频在线观看一区二区三区 | 日本久草视频 | 99精品久久 | 在线观看中文字幕一区二区 | 亚洲国产精品久久久久婷婷老年 | 久久精品国产久精国产 | 中文亚洲视频 | 成人永久免费视频 | 第一区在线观看免费国语入口 | 欧美三级成人理伦 | 激情a| 精品国产欧美一区二区三区成人 | 久久国产日本 | 亚洲成人精品视频 | 完全免费在线视频 | 精品久久久久久久久久久久久久久久久 | 日本不卡一区二区三区 | 中文字幕一区二区三区在线观看 | 午夜国产一级 | 在线超碰| 亚洲精品在线视频 | 99久久久久国产精品免费 | 亚洲日韩中文字幕一区 | 污视频在线免费观看 | 日韩三级一区 | 久久极品 | 国产视频第一页 | 中文在线日韩 | 欧美日韩福利 | 色女人天堂 | 欧洲精品码一区二区三区免费看 | 亚洲欧洲一区 | 亚洲国产黄色av | 久久在线 | 久久国产精品久久久久久久久久 | 91精品国产高清一区二区三区 |