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

How do i make a math.random with decimals?

lately, i been having a problem with math.random, i want it to do decimals how do i do this?

1 comment

0

What exactly do you want? Can you give examples of what's acceptable and what's not acceptable output? What is the range? Should some numbers be preferred over other numbers?

1 answer

math.random() will return a random decimal between 0-1.

print(math.random()) -- 0.53971289371293

If you want a more specific decimal you can always do something like this:

local x = math.random(10)/10 -- 0.1 - 1

local y = math.random(100)/100 -- 0.01 - 1

If you don't want whole numbers possible:

local x = math.random(0,9)/10 -- 0 - 0.9

x = math.random(0,90)/100 -- 0 - 0.09

1 comment

4

You can use (min + 0.5 + math.random() * ( max - min )) to generate a random number with decimals.

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