• <tfoot id='ds5gq'></tfoot>
      <bdo id='ds5gq'></bdo><ul id='ds5gq'></ul>

  • <legend id='ds5gq'><style id='ds5gq'><dir id='ds5gq'><q id='ds5gq'></q></dir></style></legend>
  • <small id='ds5gq'></small><noframes id='ds5gq'>

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

      1. 改变uniform_int_distribution的范围

        时间:2023-10-07
          <tbody id='uz3Tj'></tbody>

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

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

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

                <bdo id='uz3Tj'></bdo><ul id='uz3Tj'></ul>
                1. 本文介绍了改变uniform_int_distribution的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以我有一个随机对象:

                  So i have a Random object:

                  typedef unsigned int uint32;
                  
                  class Random {
                  public:
                      Random() = default;
                      Random(std::mt19937::result_type seed) : eng(seed) {}
                  
                  private:
                      uint32 DrawNumber();
                      std::mt19937 eng{std::random_device{}()};
                      std::uniform_int_distribution<uint32> uniform_dist{0, UINT32_MAX};
                  };
                  
                  uint32 Random::DrawNumber()
                  {
                      return uniform_dist(eng);
                  }
                  

                  我可以改变(通过另一个函数或其他方式)分布上限的最佳方法是什么?

                  What's the best way I can vary (through another function or otherwise) the upper bound of of the distribution?

                  (也愿意接受其他风格问题的建议)

                  (also willing to take advice on other style issues)

                  推荐答案

                  分发对象是轻量级的.当您需要随机数时,只需构建一个新的分布.我在游戏引擎中使用这种方法,经过基准测试后,它可以与使用旧的 rand() 相媲美.

                  Distribution objects are lightweight. Simply construct a new distribution when you need a random number. I use this approach in a game engine, and, after benchmarking, it's comparable to using good old rand().

                  此外,我在 GoingNative 2013 直播中询问了如何改变分发范围,标准委员会成员 Stephen T. Lavavej 建议简单地创建新分发,因为它不应该是表演问题.

                  Also, I've asked how to vary the range of distribution on GoingNative 2013 live stream, and Stephen T. Lavavej, a member of the standard committee, suggested to simply create new distributions, as it shouldn't be a performance issue.

                  以下是我将如何编写您的代码:

                  Here's how I would write your code:

                  using uint32 = unsigned int;
                  
                  class Random {
                  public:
                      Random() = default;
                      Random(std::mt19937::result_type seed) : eng(seed) {}
                      uint32 DrawNumber(uint32 min, uint32 max);
                  
                  private:        
                      std::mt19937 eng{std::random_device{}()};
                  };
                  
                  uint32 Random::DrawNumber(uint32 min, uint32 max)
                  {
                      return std::uniform_int_distribution<uint32>{min, max}(eng);
                  }
                  

                  这篇关于改变uniform_int_distribution的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:就生成随机数而言,种子是什么? 下一篇:跨平台一致的伪随机数

                  相关文章

                  最新文章

                  <tfoot id='yM9Tn'></tfoot>

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

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

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

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