So i've though of making a random playbackspeed generator for a weapon's audio, but i'm not used to using Random.new
. here is what i think would work...
BurnSound.PlaybackSpeed = Random.new(.8,1.1)
would this work with decimals?
(edit: i am testing this out)
It won't work with decimals. I suggest you to divide the randomized value by 10, 100 or another number:
local number = math.random(80, 110) BurnSound.PlaybackSpeed = number/100 -- the number divided by 100
Also, use math.random and not Random.new.
Hope this helped!
The answer above is well over a year now, as of August 16, 2021.
(Just adding more context, for newer developers)
Can you use decimals in Random functions?
The short answer is NO. The reason behind this is because, when this function is called below 0, i.e decimals it cannot return decimals, (only integers), it will always return 0, same goes with the math.random
function. math.random and Random both have the same type of algorithm, so it's better to use math.random, since I believe it has a little more functionality.
Quick Note:
Random.new returns a seed, what is a seed? A seed is a positive integer that initialises a random number generator.
When math.random() is called without any parameters like this:
print(math.random())
it will return a decimal between 0 and 1.