久久久久久久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() 函數的正確方法是什么?

        What#39;s the Right Way to use the rand() Function in C++?(在 C++ 中使用 rand() 函數的正確方法是什么?)
          <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() 函數的正確方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在做一個書本練習,內容是編寫一個生成偽隨機數的程序.我從簡單開始.

                  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();
                  }
                  

                  我注意到每次程序運行時,都會有相同的隨機"輸出.所以我研究了隨機數生成器,并決定通過在 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);
                  

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

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

                  所以我想我會很聰明并像這樣實現種子.

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

                  srand(rand());
                  

                  這基本上和程序最初所做的一樣,但輸出了一組不同的數字(這是有道理的,因為 rand() 生成的第一個數字總是 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. 讓用戶輸入一個數字并將其設置為種子(這很容易實現,但這是最后的手段)或
                  2. 以某種方式將種子設置為計算機時鐘或其他不斷變化的數字.

                  我是不是腦子進水了,我現在應該停下來嗎?選項 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().

                  這篇關于在 C++ 中使用 rand() 函數的正確方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 類比是什么?)
                  <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. 主站蜘蛛池模板: 五月激情婷婷在线 | 九九热国产精品视频 | 午夜久久久久久久久久一区二区 | 久久99久久99精品免视看婷婷 | 久久久久久久久久爱 | 国产一区不卡 | 午夜不卡福利视频 | 久久免费精品视频 | 欧美黄色网 | 九九精品在线 | 亚洲在线 | 精品综合网 | 国产精品日韩一区二区 | 欧美一区二区三区大片 | 国产午夜精品一区二区三区四区 | 日韩欧美一区二区三区免费观看 | 日本一区二区在线视频 | 亚洲激情综合 | 久久久精品一区二区三区 | 国产精品久久午夜夜伦鲁鲁 | 国产免费一区二区 | 久久久蜜桃 | 一区二区三区国产 | 91精品免费视频 | 亚洲成人福利在线观看 | 欧美日韩国产一区二区 | 亚洲日韩中文字幕一区 | 中文字幕亚洲视频 | 久久亚洲欧美日韩精品专区 | 涩涩导航| 精产国产伦理一二三区 | 亚洲精品无 | 亚洲视频区 | 蜜桃av鲁一鲁一鲁一鲁 | 久久久久久久久久一区二区 | 色视频在线免费观看 | 激情久久网 | 亚洲福利视频网 | 精品视频一区二区三区在线观看 | 国产精品99久久久久久动医院 | 亚洲97|