lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Adam D. Moss wrote:
Philippe Lhoste wrote:
Bad Things:
- PalmOS MathLib does not have a rand() or srand() function. If you have
one, MIT licesend, please send to us, so we can add it to the port.

I believe the Meresnne Twister <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html> was implemented in Lua or in C with Lua interface. Maybe this is an overkill for the PalmOS (I don't know if the implementation is really big or slow or memory hungry. They say it is as fast as rand(), and consumes 624 words of workplace, probably because it generates 624 numbers at each iteration)

I may as well pimp my random number generator again, since
it's probably good for low-power CPUs, though it doesn't come
with a lua binding (yet!) but that should be simple:
http://icculus.org/~aspirin/fnvrand/

It uses only a few bytes of state and is about 10x faster than
a good MT implementation, though I really doubt the quality of
randomness is comparable (but it's pretty good, from casual
analysis).

Interesting. I suppose you tested it using good statistical rules...
Oh well, you seem to have used a sane algorithm (good idea to have made the README readable without having first to download the archive...), and for most uses, MT quality isn't probably needed. After all, a lot of programs use rand() which has an awful reputation... (perhaps injust in modern implementations).

Note that I saw an MT implementation that generate numbers one by one (ie. not in batches of 624 words), so it should use less memory, perhaps at the cost of slower generation (but it seems to depend on the platform).

--
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://Phi.Lho.free.fr
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--