www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - RFC - Mersenne Twister (SFMT)

reply Tyro[a.c.edwards] <no spam.com> writes:
After reading Julienne Walker's article
(http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand() I
wondered why the very best psudo-random generator available is not the
standard. I looked at the std.random and was not happy to find out that it is
slower than I rand() so I attempted to convert Mersenne Twister (again). I'm
hoping to get some feedback on how to improve upon the attempt. The actual
library (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html) comes
with code for both 64-bit OSes and more.

D version: D v2.007
OS: Windows XP - sp2

Thanks,
Andrew
Nov 17 2007
next sibling parent reply Jason House <jason.james.house gmail.com> writes:
Tyro[a.c.edwards] wrote:

 After reading Julienne Walker's article
 (http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand() I
 wondered why the very best psudo-random generator available is not the
 standard. I looked at the std.random and was not happy to find out that it
 is slower than I rand() so I attempted to convert Mersenne Twister
 (again). I'm hoping to get some feedback on how to improve upon the
 attempt. The actual library
 (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html) comes
 with code for both 64-bit OSes and more.
 
 D version: D v2.007
 OS: Windows XP - sp2
 
 Thanks,
 Andrew
I also have a Mersenne Twister implementation available at: http://housebot.svn.sourceforge.net/viewvc/housebot/trunk/housebot/random.d?view=log
Nov 17 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Jason House wrote:
 Tyro[a.c.edwards] wrote:
 
 After reading Julienne Walker's article
 (http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand() I
 wondered why the very best psudo-random generator available is not the
 standard. I looked at the std.random and was not happy to find out that it
 is slower than I rand() so I attempted to convert Mersenne Twister
 (again). I'm hoping to get some feedback on how to improve upon the
 attempt. The actual library
 (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html) comes
 with code for both 64-bit OSes and more.

 D version: D v2.007
 OS: Windows XP - sp2

 Thanks,
 Andrew
I also have a Mersenne Twister implementation available at: http://housebot.svn.sourceforge.net/viewvc/housebot/trunk/housebot/random.d?view=log
Note: Jason's is GPLv3. --bb
Nov 17 2007
parent Jason House <jason.james.house gmail.com> writes:
Bill Baxter wrote:
 Note: Jason's is GPLv3.
... Covering 5 lines of code + imports + unit tests... The bulk of the code has a looser license. If someone wants to use it as part of D, I can (and will) get permission to remove the GPLv3 license.
Nov 17 2007
prev sibling next sibling parent reply BCS <ao pathlink.com> writes:
Reply to tyro[a.c.edwards],

 After reading Julienne Walker's article
 (http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand()
 I wondered why the very best psudo-random generator available is not
 the standard. I looked at the std.random and was not happy to find out
 that it is slower than I rand() so I attempted to convert Mersenne
 Twister (again). I'm hoping to get some feedback on how to improve
 upon the attempt. The actual library
 (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html)
 comes with code for both 64-bit OSes and more.
 
 D version: D v2.007
 OS: Windows XP - sp2
 Thanks,
 Andrew
If you want svn hosting for this you can put it in scrapple: http://www.dsource.org/projects/scrapple/ If you don't have access, send me a username and I'll add you.
Nov 17 2007
parent reply "Tyro[a.c.edwards]" <no spam.com> writes:
BCS さんは書きました:
 Reply to tyro[a.c.edwards],
 
 After reading Julienne Walker's article
 (http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand()
 I wondered why the very best psudo-random generator available is not
 the standard. I looked at the std.random and was not happy to find out
 that it is slower than I rand() so I attempted to convert Mersenne
 Twister (again). I'm hoping to get some feedback on how to improve
 upon the attempt. The actual library
 (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html)
 comes with code for both 64-bit OSes and more.

 D version: D v2.007
 OS: Windows XP - sp2
 Thanks,
 Andrew
If you want svn hosting for this you can put it in scrapple: http://www.dsource.org/projects/scrapple/ If you don't have access, send me a username and I'll add you.
Much appreciated. My user name is tyro.
Nov 18 2007
parent BCS <ao pathlink.com> writes:
Reply to tyro[a.c.edwards],


your in
Nov 18 2007
prev sibling next sibling parent reply Derek Parnell <derek psych.ward> writes:
LOL ... I did a port to D about a year or so ago, to help teach myself the
language. I'll try to dig it out for comparision. I remember adding some
extra functions and also allowing for additional entropy to be included.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Nov 17 2007
parent Matti Niemenmaa <see_signature for.real.address> writes:
Derek Parnell wrote:
 LOL ... I did a port to D about a year or so ago, to help teach myself the
 language. I'll try to dig it out for comparision. I remember adding some
 extra functions and also allowing for additional entropy to be included.
You ported MT19937, which is a bit different from the SFMT that Tyro ported. I've got the code (see attachment), but the original main function is missing. There's also Wang Zhen's port, which provides a Random class: http://lists.puremagic.com/pipermail/digitalmars-d-announce/2006-April/000816.html -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Nov 18 2007
prev sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Tyro[a.c.edwards] wrote:
 After reading Julienne Walker's article
(http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand() I
wondered why the very best psudo-random generator available is not the
standard. I looked at the std.random and was not happy to find out that it is
slower than I rand() so I attempted to convert Mersenne Twister (again). I'm
hoping to get some feedback on how to improve upon the attempt. The actual
library (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html) comes
with code for both 64-bit OSes and more.
 
 D version: D v2.007
 OS: Windows XP - sp2
 
 Thanks,
 Andrew
It looks nice. Not sure what kind of feedback you were after, but I get the feeling that there are a lot of functions there for internal use only. Those should probably be flagged private to help make it clearer what the actual user interface is. Also it's nice to give it a module declaration with a doc comment before that that explains what the module is for and the basics of how to use it. You might also want to provide a class version of the algorithm which encapsulates the state, to make thread safety easier. But it's nice to retain the global-state function-based version, since it's a little easier to work with when you don't actually need thread safety. If that's not the kind of feedback you were after then my apologies. --bb
Nov 18 2007
parent "Tyro[a.c.edwards]" <no spam.com> writes:
Bill Baxter さんは書きました:
 Tyro[a.c.edwards] wrote:
 After reading Julienne Walker's article 
 (http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx) on rand() 
 I wondered why the very best psudo-random generator available is not 
 the standard. I looked at the std.random and was not happy to find out 
 that it is slower than I rand() so I attempted to convert Mersenne 
 Twister (again). I'm hoping to get some feedback on how to improve 
 upon the attempt. The actual library 
 (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html) 
 comes with code for both 64-bit OSes and more.

 D version: D v2.007
 OS: Windows XP - sp2

 Thanks,
 Andrew
It looks nice. Not sure what kind of feedback you were after, but I get the feeling that there are a lot of functions there for internal use only. Those should probably be flagged private to help make it clearer what the actual user interface is. Also it's nice to give it a module declaration with a doc comment before that that explains what the module is for and the basics of how to use it. You might also want to provide a class version of the algorithm which encapsulates the state, to make thread safety easier. But it's nice to retain the global-state function-based version, since it's a little easier to work with when you don't actually need thread safety. If that's not the kind of feedback you were after then my apologies. --bb
Thanks --bb, in posting this, I'm was hoping for anyting advice I could get towards improving it and probably so help with the 64bit portion. This qualifies as advice and I'm very greatful. Andrew
Nov 18 2007