Reputation: 8990
i want a little php function to choose a number between 0 to 5, with 50% percent chance that it will be zero, and also choose between two strings at the same time randomly:
the algorithm:
choose number between 0,1,2,3,4,5 randomly
(50% chance for zero, 50% chance for 1,2,3,4,5)
and
choose string blue, yellow randomly
return(number, string);
can php do that in one function. cheers :)) thanks
Upvotes: 0
Views: 165
Reputation: 82078
function getPair()
{
$colors = array( "blue", "yellow" );
$elem = $colors[ rand( 0, count( $colors ) - 1 ) ];
return array( rand( 0, 1 ) * rand( 1, 5 ), $elem );
}
Upvotes: 1