You can use the rand()
function to generate a random integer between 0 and 1, and then convert that integer to a boolean.
Here's an example code block:
main.php61 chars3 lines
This code generates a random integer using rand()
, and then typecasts it to a boolean using the (bool)
syntax. The resulting boolean is stored in the $random_bool
variable.
Alternatively, you can use the mt_rand
function to generate random integers. This function is faster than rand()
, and is also more random.
Here's a code block that uses mt_rand()
instead:
main.php64 chars3 lines
Again, the resulting boolean is stored in the $random_bool
variable.
gistlibby LogSnag