Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about the <a href="http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/tutorial.html#boost_random.tutorial.generating_integers_in_a_range" rel="noreferrer">Mersenne Twister</a>? The boost implementation is rather easy to use and is well tested in many real-world applications. I've used it myself in several academic projects such as artificial intelligence and evolutionary algorithms.</p> <p>Here's their example where they make a simple function to roll a six-sided die:</p> <pre><code>#include &lt;boost/random/mersenne_twister.hpp&gt; #include &lt;boost/random/uniform_int.hpp&gt; #include &lt;boost/random/variate_generator.hpp&gt; boost::mt19937 gen; int roll_die() { boost::uniform_int&lt;&gt; dist(1, 6); boost::variate_generator&lt;boost::mt19937&amp;, boost::uniform_int&lt;&gt; &gt; die(gen, dist); return die(); } </code></pre> <p>Oh, and here's some more pimping of this generator just in case you aren't convinced you should use it over the vastly inferior <code>rand()</code>:</p> <blockquote> <p>The Mersenne Twister is a "random number" generator invented by Makoto Matsumoto and Takuji Nishimura; their website includes numerous implementations of the algorithm.</p> <p>Essentially, the Mersenne Twister is a very large linear-feedback shift register. The algorithm operates on a 19,937 bit seed, stored in an 624-element array of 32-bit unsigned integers. The value 2^19937-1 is a Mersenne prime; the technique for manipulating the seed is based on an older "twisting" algorithm -- hence the name "Mersenne Twister".</p> <p>An appealing aspect of the Mersenne Twister is its use of binary operations -- as opposed to time-consuming multiplication -- for generating numbers. The algorithm also has a very long period, and good granularity. It is both fast and effective for non-cryptographic applications.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload