Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do i generate a random number in php
Posted
Updated 25-Nov-14 5:59am
v2
Comments
DamithSL 21-Nov-14 11:56am    
smell like homework, what have you tried so far, where you stuck?

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
OriginalGriff 21-Nov-14 16:35pm    
Let's be honest here: that isn't "tried" - that's thrown together without thinking, and you are working on the "hope and pray" coding methodology...

Stop, sit down, read your course notes, and think about what you need to do.
The question itself is almost exactly the answer!
The solution is:


PHP
$var=rand($min,$max);
if($var%3 == 0){
echo "number is divisible by 3";
}
else{
echo "number is not divisible by 3 and remainder is: ".($var%3);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900