math.randomseed() argument(s)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

math.randomseed() argument(s)

Tim Hill
The Lua reference documentation for math.randomseed() (5.3 and 5.4) makes no mention of the value range for the random seed value(s). I just helped debug an app where they were feeding it a float between 0 and 1, which didn’t work since (apparently) it needs an integer value (though I’ve no idea how it would handle, for example, a negative integer value).

Might be useful to add a sentence to the Lua reference noting the expected value range?

—Tim


Reply | Threaded
Open this post in threaded view
|

Re: math.randomseed() argument(s)

Luiz Henrique de Figueiredo
> The Lua reference documentation for math.randomseed() (5.3 and 5.4) makes no mention of the value range for the random seed value(s). I just helped debug an app where they were feeding it a float between 0 and 1, which didn’t work since (apparently) it needs an integer value (though I’ve no idea how it would handle, for example, a negative integer value).
>
> Might be useful to add a sentence to the Lua reference noting the expected value range?

Indeed, math.randomseed expects an integer. Negative integers are
converted to unsigned. Here is the code:

  l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1));

Thanks for the report.