Version: 1.0
Type: Sample Code (HOWTO)
Category: Math Functions
License: GNU General Public License
Description: You can make a quick random choice between two options by seeing if the current server time seconds is even or odd. See a working version at http://www.i-fubar.com/flip-a-coin-script.php The webpage also shows how to flip a 3-sided coin.
// get the current server time in seconds
$now_seconds = date("s");
// see if it's even or odd
if(($now_seconds - (2 * floor($now_seconds/2))) == 0)
{
// the number is even
}
else
{
// the number is odd
}
/* that's it! You've flipped a coin.
See a working version here:
http://www.i-fubar.com/flip-a-coin-script.php
Includes a way to flip a 3-sided coin, too.
*/