Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you use decimals in the Random.new function?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
2
Answered by 4 years ago

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!

0
thanks speedyfox66 237 — 4y
0
nvm was gonna ask something speedyfox66 237 — 4y
0
Upvoted, answered the best way. Was going to post the same but it turned out you did before me. User#31525 30 — 4y
0
Added more of an explanation a year later, from January 23, 2020 to August 16, 2021 JesseSong 3916 — 2y
Ad
Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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.randomfunction. 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

Answer this question