hi, i would like to make a script that generates a thousand random number between 0 and 37 inclusive
then 0 and 37 are highlighted red
all other odd and evn numbers are either blue or green
is this possible please?
gsnedders
06-18-2005, 07:54 PM
<?php
$num = mt_rand(0,37);
if ($num == 0 || $num == 37)
{
echo "<span style=\"color: #f00;\">$num</span>";
}
elseif ($num % 2)
{
echo "<span style=\"color: #0f0;\">$num</span>";
}
else
{
echo "<span style=\"color: #00f;\">$num</span>";
}
?>
I *think* this is what you mean, as your request isn't completely clear.
marek_mar
06-18-2005, 08:15 PM
He also wanted a thousand numbers.
for($i = 0; $i < 1000; $i++)
{
$num = mt_rand(0, 37);
print $num;
if($num % 2)
{
print ' odd';
}
else
{
print ' even';
}
print "\n";
}
gsnedders
06-18-2005, 09:35 PM
But he also wanted the colouring, so it'd be:
<?php
for ($i = 0; $i < 1000; $i++)
{
$num = mt_rand(0,37);
if ($num == 0 || $num == 37)
{
echo "<span style=\"color: #f00;\">$num</span>";
}
elseif ($num % 2)
{
echo "<span style=\"color: #0f0;\">$num</span>";
}
else
{
echo "<span style=\"color: #00f;\">$num</span>";
}
echo '<br />';
}
?>
omg than you all :thumbsup: :thumbsup:
it works