kyren / piccolo

An experimental stackless Lua VM implemented in pure Rust
Creative Commons Zero v1.0 Universal
1.62k stars 59 forks source link

fix: math.random #48

Closed Jengamon closed 4 months ago

Jengamon commented 4 months ago

PUC-Lua has different behavior if math.random(0) is executed, as 0 is not in [1, n) for any n. This changes the code to match that behavior.

Also fixes the crash from math.random(v) where v < 0 and makes it a Lua error.

I poked the function until it cried, so I included a fix for math.random([n, ]math.maxinteger)...

kyren commented 4 months ago

Yeah, this seems right to me, thank you!