math.random(0.1,0.5) returns always 0 to me, how do i use it properly?
Use Tick(). It generates floats
How would you think of using tick? It just returns the time in seconds passed from 1st of Jan 1970
your .1-.5 means from .1 to .4 math.random() generates int so they just end up rounding to 0
well you could
local random = math.random(1,5)/10
edit:
you can make this method work with smaller numbers by something like
local random = math.random(1000,5000)/10000
just remeber use one more 0 in the dividing than the math.random
so
math.random(10,50)/100
would work
but
math.random(100,500)/10
wouldn’t
Also you should read bridelther’s post as it’s a a more effective way to get a random float
@56ytr56’s solution works, but would only give you one of five values from the set { 0.1 , 0.2 , 0.3 , 0.4 , 0.5}.
To get a random float from the range of [0.1, 0.5) you could do this:
math.random() * 0.4 + 0.1
The general formula used in mostly every programming language is random() * (max - min) + min
, assuming the random function returns a number between 0 and 1.