<tfoot id='YOKrb'></tfoot>

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

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

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

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

      1. 改变uniform_int_distribution的范围

        时间:2023-06-05
      2. <tfoot id='1iR4G'></tfoot>

          <tbody id='1iR4G'></tbody>

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

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

          <legend id='1iR4G'><style id='1iR4G'><dir id='1iR4G'><q id='1iR4G'></q></dir></style></legend>
            <bdo id='1iR4G'></bdo><ul id='1iR4G'></ul>

                  本文介绍了改变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的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文章

                    1. <small id='x9fat'></small><noframes id='x9fat'>

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