[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LJ2 vs. math.random
- From: Mike Pall <mikelu-1008@...>
- Date: Sun, 8 Aug 2010 17:39:12 +0200
Alexander Gladysh wrote:
> Lua 5.1. Manual explicitly says that math.random calls ANSI C rand() function:
>
> This function is an interface to the simple pseudo-random
> generator function rand provided by ANSI C.
The Lua manual is really two things in one: it describes the
language semantics and a particular implementation. There is no
clear separation in many cases. In this case I'm taking the
liberty to interpret this as an implementation choice.
> A friend of mine had a nasty debugging session after transition to LJ2
> from Lua, trying to figure out what's happened with his code, and why
> math.random() no longer affects C random.
I really have to question the wisdom of relying on this behavior.
Any unrelated library might use rand() and modify the state.
Thankfully most abstain from it, because of the bad API (global
modifiable state, varying number of output bits) and a history of
weak and incompatible implementations in various C libraries.
> 1. At the very least, LJ2 docs should explicitly mention this incompatibility.
I'll add it to the "features" page when I get around to adding one. :-)
--Mike