To be honest, this is such a simple problem that I'll just write the whole script. Here is a function,
roulette() that will return an array(number, colour) that you can then use in your script. I include an example of the use of the function.
<?php
function roulette($twozeroes=false)
{
// NB The parameter "twozeroes" is optional. It defaults to
// false, meaning we are using a single zero (European)
// roulette wheel. Calling the function, roulette(); is the
// same as calling, roulette(false);. For a two zero game,
// call, roulette(true);
// For PHP versions prior to 4.2.0, uncomment the next line:
// mt_srand(crc32(microtime()));
$number = rand(($twozeroes ? -1 : 0), 36);
if ($number > 0)
{
$colour = (($number % 2) == 1 ? 'red' : 'black');
} else {
$colour = 'green';
if ($number == -1)
{
$number = '00';
}
}
return array('number' => $number,
'colour' => $colour);
} // End of function roulette()
// Example of how you might use it:
$results = roulette();
?>
<p>
You spun the wheel, and here's what you get:
<font style='font-size: 25px; font-weight: bold; color:<?php echo $results['colour'];?>;'>
<?php echo $results['number'];?>
</font>
</p>
Any questions?
For the time being, you can see this script working,
>here<. It will be replaced at some point with whatever other problem I'm working on at the time.