lua-users home
lua-l archive

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


>The reason I ask is that, in my environment I 
>don't have access to the normal srand and rand >functions in the C library. What I have is a
 
This isn't an answer to your question but it may be a solution to the overall problem :-)

Have a look at:

http://www.tecgraf.puc-rio.br/~lhf/ftp/lua

and specifically:

http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/5.0/lrandom.tar.gz

which is lhf's Mersenne Twister library for Lua.

You get a library by lhf, a Lua lesson, a really decent and trusted pseudo random number generator, and a traditionally-flavoured seed() function all in a few KB of compiled object code...

I always compile this library into my Lua binary so that I have no excuse for ending up relying on some dodgy random function (e.g. rand()/srand()).

Pseudorandoms are, well, pseudo...but you may as well be as legitimately pseudo as you can :-)