Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you use decimals in the Random.new function?

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)

2 answers

✓ Accepted answer

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!

4 comments

0

thanks

0

nvm was gonna ask something

0

Upvoted, answered the best way. Was going to post the same but it turned out you did before me.

0

Added more of an explanation a year later, from January 23, 2020 to August 16, 2021

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.

##Resources:

Random - ROBLOX Developer Hub

Math functions - ROBLOX Developer Hub

This discussion is preserved as it was. New answers, comments, and votes are closed.