[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: mathlib
- From: Hisham <h@...>
- Date: Sat, 5 Apr 2014 18:01:37 -0300
On 5 April 2014 02:17, Andrew Starks <andrew.starks@trms.com> wrote:
> If anything, I think math.rand should be removed, if it cannot reasonably be
> improved within the design limitations set for Lua.
It _might_ not be able to reasonably improve within the design
limitations set of the official Lua _implementation_, but the Lua
_language_ (which is, as I understand, what is described by the Lua
Reference Manual) says only that the statistical properties of
math.rand are undefined, and therefore implementors can and do improve
on the vanilla implementation (as is the case, for example, from
math.rand in LuaJIT; the Lua implementations that run on top of the
JVM probably also implement math.rand with stronger PRNG's).
In my personal experience, having math.rand around has been very
useful and I knew the caveats of the function; they're written in the
manual. I like both facts that (a) Lua provides the function and (b)
its statistical properties are left undefined so that implementations
can improve on it. And in many cases what the official implementation
provides is really enough.
In the end, learning to deal with PRNG's is part of the learning
process of a programmer much like learning to deal with floating
point, isn't it? (In the sense that the abstractions do leak and you
have to come to terms with the way things are implemented.)
(Random thought of the day: it might have been educational if early
programming languages had called their functions of this kind prand
rather than rand... (OTOH, calling floating point numbers "float"
rather than "rational" didn't entirely abolish the confusion around
them...) )
-- Hisham