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

Best way to get a random true/false value?

I want to get either a random true or false value, but mine seems really inefficient and I'm sure there are a few much more efficient ways of doing exactly what mine does. Here's my code:

local variable
if math.random(1,2) == 1 then
	variable = true
else
	variable = false
end

My way might be the most efficient way but I don't think it is, that code is just a general way of showing what my script does, it's not the full script.

1 answer

✓ Accepted answer

The best way to do this can be done on 1 line, simply have the variable assigned to a condition. Here's the most efficient way:

local variable = math.random(1,2) == 1

That will give you a random true or false value each time.

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