Webmasters Make $$$
Webmasters Make $$$

Flip a Coin in PHP

This is a quick way to "flip a coin" -- in other words, to randomly choose between 2 options. (Further down the page is how to randomly choose between 3 options.)
First we get the number of seconds in the current time on the server. This server's time was 2:45:57 pm when you opened this page (the 57 is the number of seconds).
All we do next is check to see if the number is even or odd.
That's it. Here's a demonstration example:
Here's the result:
Reload the page to see the result change.

Flip a 3-sided coin

If you want to make a choice between 3 options, you need a three-sided coin. Here's a working example script of how to do it in PHP:
Here's the result:
Reload the page to see the result change.
Here are the complete sets of numbers:

»» More php scripts
Webmasters Make $$$
Webmasters Make $$$