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

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

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)

4 comments

2

I believe that the Random.new() constructor has a ability to make decimals, not sure though

1

Thanks. I would upvote you both, but unfortunately I don't have the ability to upvote.

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.

1 answer

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

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