I need to generate random float in Lua. It needs to be > 1, so math.random() is not a solution.
How can I do this?
I need to generate random float in Lua. It needs to be > 1, so math.random() is not a solution.
How can I do this?
This should generate random floats between 1 (inclusive) and 100 (exclusive)
math.random() + math.random(1, 99)
You can also use something like this to get a number between lower
and greater
function randomFloat(lower, greater)
return lower + math.random() * (greater - lower);
end
Just posting for fun, but you can use math.random() with no arguments to do this :P
print(math.floor((math.random()*100)+0.5))