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

      <i id='yI0pi'><tr id='yI0pi'><dt id='yI0pi'><q id='yI0pi'><span id='yI0pi'><b id='yI0pi'><form id='yI0pi'><ins id='yI0pi'></ins><ul id='yI0pi'></ul><sub id='yI0pi'></sub></form><legend id='yI0pi'></legend><bdo id='yI0pi'><pre id='yI0pi'><center id='yI0pi'></center></pre></bdo></b><th id='yI0pi'></th></span></q></dt></tr></i><div id='yI0pi'><tfoot id='yI0pi'></tfoot><dl id='yI0pi'><fieldset id='yI0pi'></fieldset></dl></div>
    2. <small id='yI0pi'></small><noframes id='yI0pi'>

      1. 每次运行程序时都是相同的随机数

        时间:2023-10-07
        <tfoot id='In5AB'></tfoot>
        <i id='In5AB'><tr id='In5AB'><dt id='In5AB'><q id='In5AB'><span id='In5AB'><b id='In5AB'><form id='In5AB'><ins id='In5AB'></ins><ul id='In5AB'></ul><sub id='In5AB'></sub></form><legend id='In5AB'></legend><bdo id='In5AB'><pre id='In5AB'><center id='In5AB'></center></pre></bdo></b><th id='In5AB'></th></span></q></dt></tr></i><div id='In5AB'><tfoot id='In5AB'></tfoot><dl id='In5AB'><fieldset id='In5AB'></fieldset></dl></div>

            <tbody id='In5AB'></tbody>
          <legend id='In5AB'><style id='In5AB'><dir id='In5AB'><q id='In5AB'></q></dir></style></legend>
            <bdo id='In5AB'></bdo><ul id='In5AB'></ul>

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

                • 本文介绍了每次运行程序时都是相同的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我每次运行游戏时输出的随机数都以相同的顺序输出.为什么会发生这种情况?

                  My random numbers that output, output in the same sequence every time I run my game. Why is this happening?

                  我有

                  #include <cstdlib> 
                  

                  并使用它来生成随机数

                  randomDiceRollComputer = 1 + rand() % 6;
                  

                  推荐答案

                  你需要为你的随机数生成器做种子:

                  You need to seed your random number generator:

                  试着把它放在程序的开头:

                  Try putting this at the beginning of the program:

                  srand ( time(NULL) );
                  

                  请注意,您需要#include .

                  这里的想法是在每次启动程序时为 RNG 设置不同的编号.通过使用时间作为种子,每次启动程序时您都会得到不同的数字.

                  The idea here is to seed the RNG with a different number each time you launch the program. By using time as the seed, you get a different number each time you launch the program.

                  这篇关于每次运行程序时都是相同的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:std::mt19937 需要预热吗? 下一篇:rand() 生成相同的数字——即使在我的主要内容中

                  相关文章

                  最新文章

                • <tfoot id='cvx0U'></tfoot>
                    <bdo id='cvx0U'></bdo><ul id='cvx0U'></ul>
                  <i id='cvx0U'><tr id='cvx0U'><dt id='cvx0U'><q id='cvx0U'><span id='cvx0U'><b id='cvx0U'><form id='cvx0U'><ins id='cvx0U'></ins><ul id='cvx0U'></ul><sub id='cvx0U'></sub></form><legend id='cvx0U'></legend><bdo id='cvx0U'><pre id='cvx0U'><center id='cvx0U'></center></pre></bdo></b><th id='cvx0U'></th></span></q></dt></tr></i><div id='cvx0U'><tfoot id='cvx0U'></tfoot><dl id='cvx0U'><fieldset id='cvx0U'></fieldset></dl></div>
                • <small id='cvx0U'></small><noframes id='cvx0U'>

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