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

How do i make a math.random with decimals?

Asked by 7 years ago

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

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? BlueTaslem 18071 — 7y

1 answer

Log in to vote
4
Answered by 7 years ago
Edited 7 years ago

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
4
You can use (min + 0.5 + math.random() * ( max - min )) to generate a random number with decimals. elijahlorden 6 — 7y
Ad

Answer this question