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

Is there a way to get a random floating point decimal value? [ANSWERED]

Asked by 5 years ago
Edited 5 years ago

I'm trying to create a GUI that goes to a random co-ordinate on the screen, but from my knowledge math.random only works with whole integers, I was thinking about dividing the math.random by 2, but then I would get a higher value than anticipated. Would my best bet be to make a table of values and chose a random index number to achieve this? or is there another stock method to get this done?

NOTE: I'm talking about absolute position of the GUI, not the offset. (Absolute is between 0 and 1 for the active view port)

2
I believe that the Random.new() constructor has a ability to make decimals, not sure though rokedev 71 — 5y
1
Thanks. I would upvote you both, but unfortunately I don't have the ability to upvote. MezornoIV 25 — 5y
0
math.random() returns a random float from 0 to 1. You can multiply this by x to get a range of floats from 0 to x. You can y to this to get floats from y to x + y. fredfishy 833 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You Could Get A Random Number Thats Higher And Divide It, For Example:

(math.random(0,100)/100)

For Two Decimal Places, or

(math.random(0,10)/10)

For One Decimal Place

Ad

Answer this question