[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Bug? in mathlib's random()
- From: Dave Bollinger <DBollinger@...>
- Date: Fri, 13 Aug 1999 21:23:56 -0400
It may just be a fault with the documentation, but random() doesn't work
as described under certain circumstances. Specifically, it doesn't handle
0 (zero) very well -- caused by the use of default values in the
luaL_opt_int() calls, I believe.
For the two-parameter form: The call "random(1,10)" works properly, but
the call "random(0,9)" behaves as the zero-parameter form and returns a
float 0..1 not an int 0..9. Easy to work-around and just subtract 1 from
the former style, but should be fixed.
For the single-parameter form: The call "random(0)" (which is probably
undefined according to the definition in the docs) also behaves as the
zero-parameter form and returns float 0..1. But that's probably preferable
to returning nil or {} to mean "undefined". Though I might have expected
it to return a constant 0 integer (since the range of l and u becomes
0..0), just as "random(1)" returns a constant 1 (since the range of l and u
becomes 1..1).
Cheers,
Dave