SOLVEDAre random Bools a thing?

Dinkaru

Member
So i was wondering if random bools were a thing, so it would give you a random true or false.

TsukaYuriko

☄️
Forum Staff
Moderator
As in irandom(1)?

Mr Magnus

Viking King
Either use irandom(1), or choose(true,false).

In GML any value higher than or equal to 0.5 is true, anything below that is false.

Dinkaru

Member
Either use irandom(1), or choose(true,false).

In GML any value higher than or equal to 0.5 is true, anything below that is false.
may you give an example?

Mr Magnus

Viking King
may you give an example?
GML:
variable = 1 // true

variable = 0 // false

variable = irandom(1) // true half the time, false half the time. Make sure you call randomize() once at the beginning of the game

variable = choose(true, false) //true half the time, false half the time

variable = choose(true, true, false) // True 2/3rd of the time, false 1/3rd of the time

variable = random(1) < 0.5 //True half the time, false half the time

variable = random(100) < 50 //true half the time, false half the time

Last edited:

Roldy

Member
variable = random(100) < 500 //true half the time, true half the time

• • Mr Magnus, Terminator_Pony and TheouAegis

TheouAegis

Member
Just like the recent staffing problems at my job - too many zeroes. chamaeleon

Member
GML:
variable = irandom(1) == 1;
variable = irandom(1) ? true : false;

GMWolf

aka fel666
GML:
variable = irandom(1) == 1;
variable = irandom(1) ? true : false;
GML:
if (((irandom(1) == 1) == true) ? true : false)
{
return true;
}
else
{
return false;
} • Mr Magnus and Terminator_Pony

Mr Magnus

Viking King
variable = random(100) < 500 //true half the time, true half the time
... I'll just quietly edit that and blame it on nondescript distractions and stressors in my life. • Roldy and Terminator_Pony

Mr Magnus

Viking King
Ignore me. I pressed the wrong green button marked "save"

• Alice

Terminator_Pony

Member
GML:
if (((irandom(1) == 1) == true) ? true : false)
{
return true;
}
else
{
return false;
} true is literally triggering, I prefer
GML:
if (((irandom(1) == 1) == !false) ? !false : false){ return !false; }else{ return false; }
Now can we discuss banker's rounding and how you can slightly improve your odds of !false using irandom(1) == 0 or irandom_range(1,2) == 2?

• • Roldy, GMWolf and Cloaked Games

Dinkaru

Member
Thanks to everyone!