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

how do i put a minimum number for math.random?

Asked by
ZITOI 0
8 years ago

look i tryed here

local number = math.random() *5 >3
print (number)

L--> false

why did it input: false? how can i finish my code?

1 answer

Log in to vote
4
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

Your code printed false because your number variable was an expression. The math.random function with no given arguments will return a randomized number between 0 and 1. You multiplied this by 5, then had the expression check whether or not it was greater than 3. Due to this, the variable turned into a bool datatype. If it was greater than 3 then it would be true, if it was less than 3 it would be false.

I think what you were looking for was an if statement.

local number = math.random() * 5 

if number > 3 then
    print (number)
end
Ad

Answer this question