The expressiveness of Haskell – Random Numbers.

Back in the 1940s the mathematician John von Neumann invented the ‘middle square’ method of generating pseudo random numbers. The algorithm starts with a 4 digit number which is then squared. If the resulting number has fewer than 8 digits then it is padded with leading zeros. From this 8 digit number the middle 4 digits are extracted and returned as the result and also as input to repeating the algorithm. This implementation, in Haskell, will manipulate the digits of the number as a list and so in outline we need to take the seed number and ‘square it‘ then Read More

ˆ Back To Top