Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Disclaimer: I am not sure what guarantee MT has in terms of cycle overlap when starting from an arbitrary "uint" (or x, where x is a smaller arbitrary but unique value) seed, but that may be worth looking into, as if there is a guarantee then it may be sufficient to just start each node on a different "uint" seed and the rest of this post becomes largely moot. (<a href="http://www.quadibloc.com/crypto/co4814.htm" rel="nofollow">The cycle length/period of MT is <em>staggering</em></a> and dividing out UINT_MAX still leaves an <em>incomprehensible</em> -- except on paper -- number.)</p> <hr> <p>Well, here goes my comments to answer...</p> <p>I like approach #2 with a pre-generated set of states; the MT in each node is then initialized with a given starting state.</p> <p>Only the initial states must be preserved, of course, and once this is generated these states can</p> <ol> <li>Be re-used indefinitely, if requirements are met, or;</li> <li>The next states can generated forward on an external fast box why the simulation is running or;</li> <li>The nodes can report back the end-state (if reliable messaging, and if sequence is used at same rate among nodes, and meets requirements, etc)</li> </ol> <p>Considering that MT is <em>fast to generate</em>, I would not recommend #3 from above as it's just complicated and has a number of strings attached. Option #1 is simple, but might not be dynamic enough.</p> <p>Option #2 seems like a very good possibility. The server (a "fast machine", not necessarily a node) only needs to transmit the starting state of the next "unused sequence block" (say, one billion cycles) -- the node would use the generator for one billion cycles before asking for a new block. This would make it a hybrid of #1 in the post with very infrequent messaging.</p> <p>On my system, a Core2 Duo, I can generate <em>one billion</em> random numbers in 17 seconds using the code provided below (it runs in <a href="http://linqpad.net" rel="nofollow">LINQPad</a>). I am not sure what MT variant this is.</p> <pre><code>void Main() { var mt = new MersenneTwister(); var start = DateTime.UtcNow; var ct = 1000000000; int n = 0; for (var i = 0; i &lt; ct; i++) { n = mt.genrand_int32(); } var end = DateTime.UtcNow; (end - start).TotalSeconds.Dump(); } // From ... and modified (stripped) to work in LINQPad. // http://mathnet-numerics.googlecode.com/svn-history/r190/trunk/src/Numerics/Random/MersenneTwister.cs // See link for license and copyright information. public class MersenneTwister { private const uint _lower_mask = 0x7fffffff; private const int _m = 397; private const uint _matrix_a = 0x9908b0df; private const int _n = 624; private const double _reciprocal = 1.0/4294967295.0; private const uint _upper_mask = 0x80000000; private static readonly uint[] _mag01 = {0x0U, _matrix_a}; private readonly uint[] _mt = new uint[624]; private int mti = _n + 1; public MersenneTwister() : this((int) DateTime.Now.Ticks) { } public MersenneTwister(int seed) { init_genrand((uint)seed); } private void init_genrand(uint s) { _mt[0] = s &amp; 0xffffffff; for (mti = 1; mti &lt; _n; mti++) { _mt[mti] = (1812433253*(_mt[mti - 1] ^ (_mt[mti - 1] &gt;&gt; 30)) + (uint) mti); _mt[mti] &amp;= 0xffffffff; } } public uint genrand_int32() { uint y; if (mti &gt;= _n) { int kk; if (mti == _n + 1) /* if init_genrand() has not been called, */ init_genrand(5489); /* a default initial seed is used */ for (kk = 0; kk &lt; _n - _m; kk++) { y = (_mt[kk] &amp; _upper_mask) | (_mt[kk + 1] &amp; _lower_mask); _mt[kk] = _mt[kk + _m] ^ (y &gt;&gt; 1) ^ _mag01[y &amp; 0x1]; } for (; kk &lt; _n - 1; kk++) { y = (_mt[kk] &amp; _upper_mask) | (_mt[kk + 1] &amp; _lower_mask); _mt[kk] = _mt[kk + (_m - _n)] ^ (y &gt;&gt; 1) ^ _mag01[y &amp; 0x1]; } y = (_mt[_n - 1] &amp; _upper_mask) | (_mt[0] &amp; _lower_mask); _mt[_n - 1] = _mt[_m - 1] ^ (y &gt;&gt; 1) ^ _mag01[y &amp; 0x1]; mti = 0; } y = _mt[mti++]; /* Tempering */ y ^= (y &gt;&gt; 11); y ^= (y &lt;&lt; 7) &amp; 0x9d2c5680; y ^= (y &lt;&lt; 15) &amp; 0xefc60000; y ^= (y &gt;&gt; 18); return y; } } </code></pre> <p>Happy coding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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