pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="3nlt7zb" 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() 函數有什么區別?

        What difference between rand() and random() functions?(rand() 和 random() 函數有什么區別?)
      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="7xnvtxz" 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() 函數有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  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() 通常是低質量的 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()的結果轉化為可以直接使用的數字,通常依賴于難讀易出錯的代碼,而使用; 分發很容易并且產生可讀的代碼.

                  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() 在給定分布中生成值的常用方法進一步降低了生成數據的質量.% 通常會使數據產生偏差,浮點除法仍然會產生非均勻分布. 分布質量更高,可讀性更強.

                  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() 不是線程安全的.一些實現可以保證線程安全,但這不是必需的標準.<random> 提供的引擎將 pRNG 狀態封裝為具有值語義的對象,允許對狀態進行靈活控制.

                  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() 只允許有限范圍的種子. 中的引擎可以使用允許最大可能種子數據的種子序列進行初始化.seed_seq 還實現了一個常見的 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() 函數有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 類比是什么?)

                  <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="rpvrvlr" 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>
                            主站蜘蛛池模板: 阿尔法-MDR2000无转子硫化仪-STM566 SATRA拉力试验机-青岛阿尔法仪器有限公司 | 广东佛电电器有限公司|防雷开关|故障电弧断路器|智能量测断路器 广东西屋电气有限公司-广东西屋电气有限公司 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 陶瓷砂磨机,盘式砂磨机,棒销式砂磨机-无锡市少宏粉体科技有限公司 | 琉璃瓦-琉璃瓦厂家-安徽盛阳新型建材科技有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 膜片万向弹性联轴器-冲压铸造模具「沧州昌运模具」 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 【直乐】河北石家庄脊柱侧弯医院_治疗椎间盘突出哪家医院好_骨科脊柱外科专业医院_治疗抽动症/关节病骨伤权威医院|排行-直乐矫形中医医院 | FFU_空气初效|中效|高效过滤器_空调过滤网-广州梓净净化设备有限公司 | 云南成考网_云南成人高考报名网 粤丰硕水性环氧地坪漆-防静电自流平厂家-环保地坪涂料代理 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 泰国试管婴儿_泰国第三代试管婴儿费用|成功率|医院—新生代海外医疗 | 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | 东莞压铸厂_精密压铸_锌合金压铸_铝合金压铸_压铸件加工_东莞祥宇金属制品 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 车载加油机品牌_ 柴油加油机厂家 | hc22_hc22价格_hc22哈氏合金—东锜特殊钢 | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 懂研帝_专业SCI论文润色机构_SCI投稿发表服务公司 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 好看的韩国漫画_韩漫在线免费阅读-汗汗漫画 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 原色会计-合肥注册公司_合肥代理记账公司_营业执照代办 | 上海办公室设计_办公楼,写字楼装修_办公室装修公司-匠御设计 | 亮点云建站-网站建设制作平台| 高柔性拖链电缆-聚氨酯卷筒电缆-柔性屏蔽电缆厂家-玖泰电缆 | 【ph计】|在线ph计|工业ph计|ph计厂家|ph计价格|酸度计生产厂家_武汉吉尔德科技有限公司 | 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 | 涡街流量计_LUGB智能管道式高温防爆蒸汽温压补偿计量表-江苏凯铭仪表有限公司 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | 过滤器_自清洗过滤器_气体过滤器_苏州华凯过滤技术有限公司 | 酒万铺-酒水招商-酒水代理| 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 高效复合碳源-多核碳源生产厂家-污水处理反硝化菌种一长隆科技库巴鲁 | 冷油器-冷油器换管改造-连云港灵动列管式冷油器生产厂家 |