PHPBuilder - Random Choices: Flip a Coin

RSS Twitter

Random Choices: Flip a Coin

by: Bill Pellowe
March 12, 2004

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 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 
  // the number is odd 

/* that's it! You've flipped a coin.
   See a working version here:
   Includes a way to flip a 3-sided coin, too.

Comment and Contribute

Your comment has been submitted and is pending approval.

Bill Pellowe



(Maximum characters: 1200). You have characters left.