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

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

          <bdo id='k6qbn'></bdo><ul id='k6qbn'></ul>
      1. <tfoot id='k6qbn'></tfoot>

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

      2. 如何从 rand() 缩小数字?

        时间:2023-06-05
        • <bdo id='Lir25'></bdo><ul id='Lir25'></ul>
          <i id='Lir25'><tr id='Lir25'><dt id='Lir25'><q id='Lir25'><span id='Lir25'><b id='Lir25'><form id='Lir25'><ins id='Lir25'></ins><ul id='Lir25'></ul><sub id='Lir25'></sub></form><legend id='Lir25'></legend><bdo id='Lir25'><pre id='Lir25'><center id='Lir25'></center></pre></bdo></b><th id='Lir25'></th></span></q></dt></tr></i><div id='Lir25'><tfoot id='Lir25'></tfoot><dl id='Lir25'><fieldset id='Lir25'></fieldset></dl></div>
            • <small id='Lir25'></small><noframes id='Lir25'>

                  <tfoot id='Lir25'></tfoot>
                    <tbody id='Lir25'></tbody>

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

                  本文介绍了如何从 rand() 缩小数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码每秒输出一个随机数:

                  The following code outputs a random number each second:

                  int main ()
                  {
                      srand(time(NULL)); // Seeds number generator with execution time.
                  
                      while (true)
                      {
                          int rawRand = rand();
                  
                          std::cout << rawRand << std::endl;
                  
                          sleep(1);
                      }
                  }
                  

                  如何缩小这些数字的大小,使其始终在 0-100 的范围内?

                  How might I size these numbers down so they're always in the range of 0-100?

                  推荐答案

                  如果您使用的是 C++ 并且关心良好的分布,您可以使用 TR1 C++11 .

                  If you are using C++ and are concerned about good distribution you can use TR1 C++11 <random>.

                  #include <random>
                  
                  std::random_device rseed;
                  std::mt19937 rgen(rseed()); // mersenne_twister
                  std::uniform_int_distribution<int> idist(0,100); // [0,100]
                  
                  std::cout << idist(rgen) << std::endl;
                  

                  这篇关于如何从 rand() 缩小数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:某个范围内的随机数 c++ 下一篇:提升随机数生成器

                  相关文章

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

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

                    <small id='1HQUF'></small><noframes id='1HQUF'>