GLBasic forum

Codesnippets => Math => Topic started by: Hatonastick on 2009-Feb-15

Title: Mersenne Twister PRNG.
Post by: Hatonastick on 2009-Feb-15
The Mersenne Twister pseudo random number generator integrated into GLBasic via INLINE.  Except for the squashing of any bugs found, I consider this finished.  So there will be no further updates other than bug fixes.  Enjoy!

Updated 17/02/2009 (3 times today actually):  There have been numerous changes.
Updated 24/02/2009: Very minor change and updated contact information.

Note: This is now included as an attachment as the code (due to the 1000 official test numbers I'm guessing) is now larger than this board allows in a message.

[attachment deleted by admin]
Title: Re: Mersenne Twister PRNG.
Post by: Moru on 2010-Mar-13
Confirmed working on GP2X F100 :-) Nice job!
Title: Re: Mersenne Twister PRNG.
Post by: Hatonastick on 2010-Jul-08
Glad to hear it. :)

Due to my account recreation I have no control over the original post, so am posting the slightly updated version here.  When I say updated the source hasn't changed (other than minor neatening up), just that it now has a separate document as the comments etc. have been moved from inside the source code to a PDF file.  Unfortunately the PDF has greatly increased the file size. :)

Edit: Just updated the PDF a little.  No other changes from the previous version posted in this post.

Edit: Ok updated the documentation, added the info from Ocean and changed the name of the init functions to something that they should have been in the first place ie. MTSeed and MTArraySeed.  Otherwise it's the same code and not worth re-downloading if you already have it.

[attachment deleted by admin]
Title: Re: Mersenne Twister PRNG.
Post by: Hatonastick on 2010-Jul-09
Thanks mate, all added to the documentation. :)

I've really got to stop working utilities and libraries (current one is a crypto library which still needs a LOT of work) and start working on a game before I go crazy.
Title: Re: Mersenne Twister PRNG.
Post by: Hatonastick on 2010-Jul-09
Oh I think I find them more interesting to make too, but for some reason I still have a burning desire to make games even though I've never finished one (and yet have finished many libraries and utilities).  I think the reason why a MUD is the closest I've ever gotten is that for the most part it feels like you are coding a utility. :blink:
Title: Re: Mersenne Twister PRNG.
Post by: Hatonastick on 2010-Aug-20
Ok thanks for that Ocean.
Title: Re: Mersenne Twister PRNG.
Post by: Marmor on 2011-Jan-22
generate this code on all plattforms the same rnd() at first ??
Title: Re: Mersenne Twister PRNG.
Post by: Moebius on 2011-Jan-23
It was 'RND()' not 'MD()'  ;)  I read as md() first as well....
Marmor: Have you seeded it like in the example?  GLB gives RND a starting point internally when you run the program, but you need to do it yourself with this library.

Anyway, very nicely done Hatonastick!

It seems to be more than 50X FASTER than GLB's RND on my PC!   :O
Does anyone else get similar results?
Title: Re: Mersenne Twister PRNG.
Post by: Moebius on 2011-Jan-23
Confirmed working on iOS for me  =D
Again the Mersenne Twister PRNG is faster than GLB's RND by a factor of 50!
Title: Re: Mersenne Twister PRNG.
Post by: Kitty Hello on 2011-Jan-24
Yes. My RND is a very complex one, that does a very good job to give really random numbers. Like: there must be a chance that the same number is generated 3x in a row, as well as one number never being picked at all...
Title: Re: Mersenne Twister PRNG.
Post by: Moebius on 2011-Jan-25
Oh okay =D