I don't have any experience with Lua, so sorry if this doesn't help, but the way I've always been told is the standard for generating random numbers in other languages is
which should give you a floating point number between 0 and 1, multiplied by three, ultimately giving you a floating point number between 0 and 3. So to generate an integer just round the resultCode:math.random()*3
The documentation I have doesn't list math.round as being available, but if it isn't you can use either math.ceil or math.floor to descriminate between rounding up or down respectively.Code:math.round(math.random()*3)
But, looking at the Lua documentation, the way you coded it looks like it should be valid... But, in the past I've had problem with random numbers when I haven't stuck to this methoud, so hope it helps...
Bookmarks