|
help with rand function...
Hi there,
Disclaimer: This is my 3rd day learning PHP, so the following is likely going to sound silly:
Problem: The book I am using to teach myself (PHP5/MySQL for the absolute beginner by Andy Harris) has "challenges" at the end of each chapter, and I am stuck on a simple one...
"Write a 'loaded dice' program that half the time generates the value 1 and half the time generates some other value"
The basic die rolling looks like this:
<?
$roll = rand(1,6);
print "You rolled a $roll";
?>
When the html page containing the code is refreshed, it regenerates with a new random roll number.
My first idea was to make if statements for half of the possible numbers rolled (1-3 or 4-6, for a 6 sided die etc.) and then just have PHP print "You rolled a one" - but that won't really be "half of the time" because, well, it's random...
Am I missing some really simple here? Or is there another function I could add in to help in delivering the "1" value 50% of the time?
TIA for any help.
|