BASIC

Author Topic: Mersenne Twister PRNG.  (Read 7528 times)

Hatonastick

  • Guest
Mersenne Twister PRNG.
« 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]
« Last Edit: 2009-Mar-05 by Hatonastick »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1751
    • View Profile
    • Homepage
Re: Mersenne Twister PRNG.
« Reply #1 on: 2010-Mar-13 »
Confirmed working on GP2X F100 :-) Nice job!

Offline Hatonastick

  • Dr. Type
  • ****
  • Posts: 474
  • Amstrad CPC 6128
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #2 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]
« Last Edit: 2010-Aug-30 by Hatonastick »
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Offline Hatonastick

  • Dr. Type
  • ****
  • Posts: 474
  • Amstrad CPC 6128
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #3 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.
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Offline Hatonastick

  • Dr. Type
  • ****
  • Posts: 474
  • Amstrad CPC 6128
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #4 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:
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Offline Hatonastick

  • Dr. Type
  • ****
  • Posts: 474
  • Amstrad CPC 6128
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #5 on: 2010-Aug-20 »
Ok thanks for that Ocean.
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 908
  • 96A285CC
    • View Profile
    • my youtube channel
Re: Mersenne Twister PRNG.
« Reply #6 on: 2011-Jan-22 »
generate this code on all plattforms the same rnd() at first ??

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #7 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?
« Last Edit: 2011-Jan-23 by Serpent »
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #8 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!
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10661
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Mersenne Twister PRNG.
« Reply #9 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...

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Mersenne Twister PRNG.
« Reply #10 on: 2011-Jan-25 »
Oh okay =D
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary