Mersenne Twister?

Baveco, Hans Hans.Baveco at wur.nl
Thu Jan 26 07:57:05 UTC 2006


Hi Andreas,

The attached squeak implementation of the TT800 algorithm (related to MT
it seems, but with a period of 2^800 instead of 2^19937 -1) was send to
the list in 1999, by (the late?) Dave N Smith. Maybe it is of use here?

Hans
 

-----Original Message-----
From: Andreas Raab [mailto:andreas.raab at gmx.de] 
Sent: woensdag 25 januari 2006 8:00
To: The general-purpose Squeak developers list
Subject: Mersenne Twister?

Hi Folks -

Does anyone know a good (Squeak/Smalltalk) implementation of the
Mersenne Twister? I have a task for which I don't really trust good ol' 
Random and would like to use an alternative PRNG instead.

Thanks,
   - Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Random-TT800.4Nove333pm.cs
Type: application/octet-stream
Size: 11183 bytes
Desc: Random-TT800.4Nove333pm.cs
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060126/09d0aeb5/Random-TT800.4Nove333pm.obj
-------------- next part --------------
Baveco,  Dr. J.M.
From:	David N. Smith (IBM) [dnsmith at watson.ibm.com]
Sent:	Thursday, November 04, 1999 9:41 PM
To:	squeak at cs.uiuc.edu
Subject:	Re: TT800 (was RE: PRNGs  (was [Q] Project: Better performance for LargeIntegers))
At 14:09 -0500 11/2/99, Jeff Szuhay wrote:
>>At 13:25 -0500 11/2/99, Jeff Szuhay wrote:
>>>...SNIP...
>>>and finally,
>>>
>>>tt800 source code: <http://random.mat.sbg.ac.at/ftp/pub/daa/tt800.c>
>>
>>Jeff:
>>
>>Can you check this link again? I can get to 
>>http://random.mat.sbg.ac.at/ftp/pub but the daa directory is 
>>missing and nothing else seems to have a tt800.c file.
>
>Oops...
>
>change .../daa/...  to ... /data/...
>and the page will appear.

OK, I got it and have converted it to Squeak (with some testing 
assistance from Jeff). The code is attached. It's basically a 
straight conversion from C. It uses, by its nature, 32-bit long 
integers and is slow by a factor of about 30 relative to Squeak's 
Random class.

References and abstracts to the papers are included in the class 
comment. The original C code (less its tiny main program) is in a 
method as a comment. There are class methods that test the generator 
and also assure that it answers the same results as the C version.

This is a good example of why long integers need to be fast, and how 
easy it is to hit that performance brick wall.

If you are using Random, you can try this by changing the class name 
to RandomTT800. The #next method answers the next pseudo-random 
number and #seed: resets the seed. The generator automatically self 
seeds from the millisecond clock.

Dave



More information about the Squeak-dev mailing list