lua-users home
lua-l archive

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


> If anything, I think math.rand should be removed, if it cannot reasonably
> be improved within the design limitations set for Lua.

I don't think the design is wrong. Like I've mentioned here before, I was
under the impression that modern libc had reasonable rand(), though I
can't find a reference for that. In any case, there is nothing wrong with
the specs of rand() in C. It is just that traditionally rand() has been
implemented as a simple linear congruential generator. There is nothing to
prevent rand() in libc to be much better than that. I never understood why
BSD introduced random() when all it needed to do was to provide a better
rand(), except that random() and then rand48() family generate long, not
int. This was probably deemed important when int had 16 bits but is moot
now.

The intention of math.random() in Lua is to provide a convenient way
to generate random nummbers on Lua for simple applications like games,
simulations, and even throw-away passwords. Sophisticated applications such
as crytpography and serious simulations, have other needs and a better
served by specialized libraries such as OpenSSL. No one writing such an
application would rely on any built-in random number generator anyway.

Given this, Lua relying on rand() from C is not a bad choice, but it
warrants that note in the manual.