<legend id='4doDH'><style id='4doDH'><dir id='4doDH'><q id='4doDH'></q></dir></style></legend>
    • <bdo id='4doDH'></bdo><ul id='4doDH'></ul>

      <small id='4doDH'></small><noframes id='4doDH'>

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

      1. <tfoot id='4doDH'></tfoot>
      2. 提升随机数生成器

        Boost random number generator(提升随机数生成器)
      3. <small id='H3kS7'></small><noframes id='H3kS7'>

        <tfoot id='H3kS7'></tfoot>

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

                • 本文介绍了提升随机数生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有人有最喜欢的 boost 随机数生成器吗?你能解释一下如何将它实现到代码中吗?我试图让梅森龙卷风工作,并想知道是否有人偏爱其他人.

                  Does anyone have a favorite boost random number generator and can you explain a little on how to implement it into code. I am trying to get the mersenne twister to work and was wondering if anyone had preference towards one of the others.

                  推荐答案

                  此代码改编自 http://www.boost.org/doc/libs/1_42_0/libs/random/index.html:

                  #include <iostream>
                  #include "boost/random.hpp"
                  #include "boost/generator_iterator.hpp"
                  using namespace std;
                  
                  int main() {
                        typedef boost::mt19937 RNGType;
                        RNGType rng;
                        boost::uniform_int<> one_to_six( 1, 6 );
                        boost::variate_generator< RNGType, boost::uniform_int<> >
                                      dice(rng, one_to_six);
                        for ( int i = 0; i < 6; i++ ) {
                            int n  = dice();
                            cout << n << endl;
                       }
                  }
                  

                  解释一下:

                  • mt19937 是梅森扭曲器生成器,它生成原始随机数.此处使用了 typedef,因此您可以轻松更改随机数生成器类型.

                  • mt19937 is the mersenne twister generator,which generates the raw random numbers. A typedef is used here so you can easily change random number generator type.

                  rng 是twister 生成器的一个实例.

                  rng is an instance of the twister generator.

                  one_to_six分布的一个实例.这指定了我们要生成的数字及其遵循的分布.这里我们想要 1 到 6 个,均匀分布.

                  one_to_six is an instance of a distribution. This specifies the numbers we want to generate and the distribution they follow. Here we want 1 to 6, distributed evenly.

                  dice 是获取原始数字和分布的东西,并为我们创建我们真正想要的数字.

                  dice is the thing that takes the raw numbers and the distribution, and creates for us the numbers we actually want.

                  dice() 是对 dice 对象的 operator() 调用,该对象获取紧随其后的下一个随机数分布,模拟随机六面掷骰子.

                  dice() is a call to operator() for the dice object, which gets the next random number following the distribution, simulating a random six-sided dice throw.

                  就目前而言,这段代码每次都会产生相同的掷骰子序列.您可以在其构造函数中随机化生成器:

                  As it stands, this code produces the same sequence of dice throws each time. You can randomise the generator in its constructor:

                   RNGType rng( time(0) );   
                  

                  或使用其 seed() 成员.

                  or by using its seed() member.

                  这篇关于提升随机数生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                  Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                  What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                  What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)

                    <small id='4PQGh'></small><noframes id='4PQGh'>

                    • <legend id='4PQGh'><style id='4PQGh'><dir id='4PQGh'><q id='4PQGh'></q></dir></style></legend>

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

                            <tbody id='4PQGh'></tbody>

                            <tfoot id='4PQGh'></tfoot>