lua-users home
lua-l archive

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


On 12/24/2014 3:33 PM, Edward Berner wrote:
On 12/22/2014 6:34 AM, Luiz Henrique de Figueiredo wrote:
Lua 5.3.0 (rc2) is now available for testing at
    http://www.lua.org/work/lua-5.3.0-rc2.tar.gz

MD5    61726271cf342794909a1752ea0c0aae  -
SHA1    457be7b889f7825c3b9c8b9a4b95b85c0c0b434d  -

This is a release candidate for the final release of Lua 5.3.0.

A few things have changed since beta that we'd like to test in the wild.
In particular, we made some changes in luaconf.h and in the Makefile
that we'd like to test. Please try compiling the current code in as many
platforms as possible. We expect the compilation will go smoothly as usual
but please report any warnings or other glitches.


Solaris is being a bit of a pain.
[...]
I haven't spent enough time yet with the test suite on Solaris to say whether there are any issues worth reporting.



Lua's math.random(), when called with no arguments, is supposed to return a number between 0 and 1. But, on Solaris 10 (compiled with the default flags, which includes LUA_USE_POSIX):

Lua 5.3.0  Copyright (C) 1994-2014 Lua.org, PUC-Rio
> math.random()
63443.513580322

(Lua 5.2.3 works as expected because it uses rand() instead of random().)

It looks like, according to the standard ( http://pubs.opengroup.org/onlinepubs/9699919799/functions/random.html ), random() isn't actually defined in terms of RAND_MAX, even though the Linux man page (at least on CentOS 6.6) and glibc 2.8 documentation describe it that way. The Posix standard, the man pages on OpenBSD and Solaris, and the glibc 2.20 documentation describe random() as returning a number from 0 to (2**31)-1. Linux and OpenBSD set RAND_MAX to (2**31)-1, so it doesn't make much difference, but Solaris sets RAND_MAX to 32767.

Maybe lmathlib.c could abstract RAND_MAX to l_rand_max, similar to l_rand and l_srand.

Or, maybe Lua could have its own pseudorandom number generator. SQLite contains a public domain implementation of an RC4 based PRNG, for example.

Either way, I don't know that it is worth fixing now. Maybe in a point release or something. I don't feel strongly about it, I just wanted to point it out.

--
Edward Berner