[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (rc2) now availablejj
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 27 Dec 2014 10:55:26 -0200
> 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.
You are right. The Linux documentation is misleading. We will fix random.
-- Roberto