View Single Post
Old 04-14-2005, 09:23 PM   #2 (permalink)
CreativeLogic
The Acquainted
 
Join Date: Mar 2005
Posts: 177
Thanks: 0
CreativeLogic is on a distinguished road
Default

First off, it's not too bad. At least you're using switch logic and not if. That usually takes people more time to learn.

First off:
Quote:
Originally Posted by php.net
As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
Second off:
It's good practice not to name variables the same as a php function, ie: rand and $rand.

Third off:
$rand = (rand()%4);
That line is going to return 4 numbers, 0-3. One thing you'll need to get used to is that a lot of things with programming start with 0 rather than 1. That's why you're getting a blank every once in a while because you have 0 being included in there and it's not being taken care of in the switch logic. So with that being said, change %4 to %3 and use numbers 0-2 rather than 1-3.

Forth off:
Kind of changing what I said before, but you could use just rand and not do that line you had before.
So do: rand(1,3)
This would return numbers 1-3 not 0-2 like I mentioned above.

Firth off:
You don't need that variable. Just put rand(1,3) in the switch statement.
Let me know if you need any furthre explaination! :)
CreativeLogic is offline  
Reply With Quote