Mersenne Twister implentation

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Mersenne Twister implentation (/thread-7716.html)



Mersenne Twister implentation - KeithB - 02-04-2017 10:19 AM

Based on the discussion in the random number thread, here is an implementation of the Mersenne Twister.

To use, call Twister which will set up the state in the list L9(). I used a list instead of a matrix since a list can store integers. After the initial Setup you can call:

MTSEED(number) to reset the seed.
RANDMT() to get a uniform number from 0 to 1
RANDMTI() to get the raw hex numbers
RANDMTN() to get normally distributed numbers with a mean of 0 and SD of 1.

Observations:
The output matches the reference implementations exactly.
Bit twiddling is not the Prime's strong suit. (Dogs walking on their hind legs come to mind)
It is much slower than the built in functions. My random pi program is slowed down by a factor of about 20, 21.5 sec for 10000 iterations vs 1.2 sec for 10000 iterations using the built-in rand.