lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP: random numbers
Been requiring a lot of random numbers lately. Some simple routines I find useful for games of chance:

// virtual coin toss
$coinflip = mt_rand(1,2);


// actual virtual coin toss
if ( mt_rand(1,2) % 2 == 0 )
{
$flip = 'heads';
}
else
{
$flip = 'tails';
}


// roll the bones
$roll = mt_rand(1,6);