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

    1. <legend id='A5Ynv'><style id='A5Ynv'><dir id='A5Ynv'><q id='A5Ynv'></q></dir></style></legend>

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

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

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

        在 C++ 中使用 rand() 函數(shù)的正確方法是什么?

        What#39;s the Right Way to use the rand() Function in C++?(在 C++ 中使用 rand() 函數(shù)的正確方法是什么?)
          <bdo id='YdTNM'></bdo><ul id='YdTNM'></ul>
        • <legend id='YdTNM'><style id='YdTNM'><dir id='YdTNM'><q id='YdTNM'></q></dir></style></legend>

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

              <tbody id='YdTNM'></tbody>

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

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

                  本文介紹了在 C++ 中使用 rand() 函數(shù)的正確方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在做一個書本練習(xí),內(nèi)容是編寫一個生成偽隨機數(shù)的程序.我從簡單開始.

                  I'm doing a book exercise that says to write a program that generates psuedorandom numbers. I started off simple with.

                  #include "std_lib_facilities.h"
                  
                  int randint()
                  {
                      int random = 0;
                      random = rand();
                      return random;
                  }
                  
                  int main()
                  {
                      char input = 0;
                      cout << "Press any character and enter to generate a random number." << endl;
                      while (cin >> input)
                      cout << randint() << endl;
                      keep_window_open();
                  }
                  

                  我注意到每次程序運行時,都會有相同的隨機"輸出.所以我研究了隨機數(shù)生成器,并決定通過在 randint() 中首先包含它來嘗試播種.

                  I noticed that each time the program was run, there would be the same "random" output. So I looked into random number generators and decided to try seeding by including this first in randint().

                      srand(5355);
                  

                  它一遍又一遍地生成相同的數(shù)字(我現(xiàn)在覺得實現(xiàn)它很愚蠢.)

                  Which just generated the same number over and over (I feel stupid now for implementing it.)

                  所以我想我會很聰明并像這樣實現(xiàn)種子.

                  So I thought I'd be clever and implement the seed like this.

                  srand(rand());
                  

                  這基本上和程序最初所做的一樣,但輸出了一組不同的數(shù)字(這是有道理的,因為 rand() 生成的第一個數(shù)字總是 41.)

                  This basically just did the same as the program did in the first place but outputted a different set of numbers (which makes sense since the first number generated by rand() is always 41.)

                  我唯一能想到的讓這更隨機的是:

                  The only thing I could think of to make this more random is to:

                  1. 讓用戶輸入一個數(shù)字并將其設(shè)置為種子(這很容易實現(xiàn),但這是最后的手段)或
                  2. 以某種方式將種子設(shè)置為計算機時鐘或其他不斷變化的數(shù)字.

                  我是不是腦子進(jìn)水了,我現(xiàn)在應(yīng)該停下來嗎?選項 2 難以實施嗎?還有其他想法嗎?

                  Am I in over my head and should I stop now? Is option 2 difficult to implement? Any other ideas?

                  提前致謝.

                  推薦答案

                  選項 2 并不難,給你:

                  Option 2 isn't difficult, here you go:

                  srand(time(NULL));
                  

                  你需要為 srand() 包含 stdlib.h 和為 time() 包含 time.h代碼>.

                  you'll need to include stdlib.h for srand() and time.h for time().

                  這篇關(guān)于在 C++ 中使用 rand() 函數(shù)的正確方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='gKbf2'><style id='gKbf2'><dir id='gKbf2'><q id='gKbf2'></q></dir></style></legend>
                      <tbody id='gKbf2'></tbody>

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

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

                          <tfoot id='gKbf2'></tfoot>

                          1. <i id='gKbf2'><tr id='gKbf2'><dt id='gKbf2'><q id='gKbf2'><span id='gKbf2'><b id='gKbf2'><form id='gKbf2'><ins id='gKbf2'></ins><ul id='gKbf2'></ul><sub id='gKbf2'></sub></form><legend id='gKbf2'></legend><bdo id='gKbf2'><pre id='gKbf2'><center id='gKbf2'></center></pre></bdo></b><th id='gKbf2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gKbf2'><tfoot id='gKbf2'></tfoot><dl id='gKbf2'><fieldset id='gKbf2'></fieldset></dl></div>
                          2. 主站蜘蛛池模板: 色多多在线观看 | 中文在线观看免费视频 | 三级网站在线播放 | 成人国产在线 | 国产三级在线 | 亚洲欧美日韩一区二区三区四区 | 男女操网站 | 日本在线一区二区三区 | 日本熟妇毛耸耸xxxxxx | 精品在线免费视频 | 国产激情一区二区三区 | 亚洲特级片| 天天视频国产 | 午夜成人在线视频 | 日韩av一区二区在线观看 | 日韩中文字幕在线视频 | 9l视频自拍九色9l视频成人 | 操碰在线视频 | 日本国产精品 | 在线观看欧美日韩视频 | 91欧美激情一区二区三区成人 | 538在线 | www.精品| 欧美日韩成人在线 | 日韩精品久久久久 | 在线看黄的网站 | a级片在线 | 欧美一级免费 | 国产成人一区二区三区 | 日韩欧美在线视频观看 | 激情小说在线视频 | 成人在线视频免费 | 国产午夜影院 | 97在线超碰| 亚洲一区二区三区视频 | 日韩精品一区二区在线 | 在线黄色网 | 黄色精品| 国产精品123区| 国产一区二区日韩 | 黄视频免费观看 |