using index variables for clarity inside the for loops and changed
looping order
added a comment about the choice of Mersenne-Twister