PolyMathOrg / PolyMath

Scientific Computing with Pharo
MIT License
169 stars 41 forks source link

Tidy Up Mersenne Twister's nextInteger Method #136

Open hemalvarambhia opened 5 years ago

hemalvarambhia commented 5 years ago

By far the hardest to understand section of the Math-Random package is the PMMersenneTwisterRandomGenerator class's nextInteger method - it is a little long. The proposal here is to break it up into the key steps (refactor to composed method - see Kent Beck's Smalltalk Best Practise Patterns book) outlined in the original paper.

It's interesting to note that the wiki article on Mersenne-Twister talks about the idea of a twist transformation that is neither discussed in the original paper or in the Smalltalk algorithm. Should it be?

Also, we might consider finding some acceptance tests to help refactor the code with confidence. I tried using defect injection, where I incremented mti twice to see if a/some test/s failed and it/they didn't but maybe what I did isn't the correct approach.

hemalvarambhia commented 5 years ago

The tests here seem useful: https://github.com/pigulla/mersennetwister/blob/master/tests/MersenneTwister.spec.js