From: Robert Feldt Date: 2001-11-30T01:42:16+09:00 Subject: [ruby-talk:26931] Re: ANN: RandomR 0.1.0 On Fri, 30 Nov 2001, Yukihiro Matsumoto wrote: > Hi, > Hi, > In message "[ruby-talk:26820] Re: ANN: RandomR 0.1.0" > on 01/11/29, Robert Feldt writes: > > |BTW, I noticed that the inventors of the Mersenne Twister now allow > |commercial use so it might now be used in for example the Ruby source > |without licensing problems. I don't think that's ok with the faster code > |based on Shawn Cokus used here but anyway... > > Is it possible and realistic to replace Ruby's RNG by Mersenne > Twister? > Well, its in my reality but I don't know if thats enough... ;-) Here's from the MT authors web site: "Permission of Commercial Use of Mersenne Twister, 2001/Apr. 6th So far, MT has been delivered under GNU Public License. This has been an obstruction for adopting MT in commercial software. We Makoto Matsumoto and Takuji Nishimura decided to let MT be used in commercial products freely. We prepared a tar-file mt19937.tar which includes C-codes for integers, reals, and the example of outputs (Nishimura's version, not Cokus's version), under the "Artistic License", which permits commercial use." So if you pick the code at that page it should be ok. I don't think its very fast so here's the top three other implementations with their respective licenses and speed relative Wagners: 1. Geoff Kuenning, LGPL, 25-35% faster than Wagner, http://fmg-www.cs.ucla.edu/geoff/mtwist.html 2. Richard Wagner, LGPL, from the MT home page 3. Shawn Cokus, LGPL, 10% slower than Wagner Oh, all are LGPL. Is that ok? RandomR is based on Wagners (I hadn't found Kuenning's when writing it) and it was about 15% slower than Ruby's rand on my Win2k Pro with Cygwin. This is on average since the MT is very fast on 624 calls and then recalculates 624 new values so significantly slower. I don't know if this "time assymetry" is a problem. I don't think it is in the majority of cases. I don't know if its realistic since I don't know your criteria but here are some facts: * Object file for RandomR is around 20k on my machine but can probably be made smaller. I think Wagners version (without any Ruby wrapping) was 8Kb or so and Geoff's even smaller so should not grow the Ruby lib too much. * RandomR C file has around 300 LOC (from wc -l). * When you consider this you should know that it supports more stuff than rand/srand: You can have multiple streams at the same time, marshaling etc. * If basing it on Kuennings version I think it will be faster than rand even on average. * MT is definetely "better" than most other PRNG's. Very random so to say. If you decide its a good thing then maybe add a RNG class (not sure about a good name; I used long names but if its going into the std Ruby it might be better with a short name. IMHO not "Random" since its too general) to Math, add global for the default instance used to implement rand and srand. To sum up I'd say its possible (if LGPL is ok it can be very fast) and realistic (pretty small overhead and the code is there). Regards, Robert