How to create random float in lua?

I need to create an arbitrary float in Lua. It must be> 1, so math.random () is not a solution.

How can i do this?

+8
random lua
source share
3 answers

This should generate random floats between 1 (inclusive) and 100 (exclusive)

math.random() + math.random(1, 99) 
+8
source share

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 
+6
source share

Just post for fun, but you can use math.random () with no arguments for this: P

 print(math.floor((math.random()*100)+0.5)) 
+1
source share

All Articles