You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would be useful in situations where it is necessary to revert to an arbitrary midpoint through a random progression. Currently, it is possible just by manually controlling mti and mt, but ideally a user would not need to understand the inner-workings of the mersenne twister in order to manage its state.
The text was updated successfully, but these errors were encountered:
Worth note: I did not take the time to properly understand this RNG before writing the above. So, it is possible that there are other state variables that would need to be included that I missed.
That being stated, the following test code would suggest strongly against that I have succeeded:
importMersenneTwisterfrom"mersenne-twister";letgen=newMersenneTwister();//Warm up the twisterfor(leti=0;i<1000;i++){gen.random_int();}//Store the state of the twisterletostate=gen.mt.slice();letomti=gen.mti;//Generate and store a large number of sequential samples of the twisterletntest=10000;letfirstrun=[];for(leti=0;i<ntest;i++){firstrun.push(gen.random_int());}//Revert to the stored stategen.mt=ostate.slice();gen.mti=omti;//Generate another large set of similar length of numbers.//Compare each one to the original set.//Each should be identical if the state was fully captured.//Count the number of failures.letfailures=0;letpasses=0;for(leti=0;i<ntest;i++){leta=gen.random_int();letb=firstrun[i];console.log(a,b);if(a!==b){failures+=1;}else{passes+=1;}}console.log("\n\n\n"+failures+" failures, "+passes+" passes.");
Finally, since I used es6 import syntax, if you want to run this without thinking too hard about it, make sure the extension is .mjs, and use: node --experimental-modules mersennetest.mjs
Variables mt and mti appear to fully determine the state of the generator.
I suggest implementing functions get_state and set_state that respectively return and receive a state object containing the keys mt and mt.
For Example:
This would be useful in situations where it is necessary to revert to an arbitrary midpoint through a random progression. Currently, it is possible just by manually controlling mti and mt, but ideally a user would not need to understand the inner-workings of the mersenne twister in order to manage its state.
The text was updated successfully, but these errors were encountered: