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.
By far the hardest to understand section of the
Math-Random
package is thePMMersenneTwisterRandomGenerator
class'snextInteger
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.