What's the best way to simulate the concept of flipping a coin in PHP?
I need to random between true
and false
.
Is mt_rand(0, 1)
a good solution?
Short answer: Yes.
Long answer: Make sure you seed well you random number generator, so you're sure that your result lists are various. Ok, this wasn't a so long answer, after all, but still yes, rolling a random between 0 and 1 looks like the fastest way to have a random true/false value.
Well, it depends on how statistically accurate you need to be. Super-high-quality random number generators use atmospheric noise and other "true" sources of randomness.
But, for the vast majority of cases, yes a simple rand() is fine.