php generate random number
php generate random number |
mt_rand(min,max) or rand(min,max) (tip: max and min are integer value) tag are use to generate random integer ..if you want generate number between 5 to 20 you can use mt_rand(5,20) or rand(5,20)..
Just Follow the below Example how to Generate Random number
PHP Generate Random Number Example:
Example 1: phprand.php
<?php $number=rand(5,20); $number2=mt_rand(5,20); echo $number.'<br/>'; echo $number2; ?>
Example 2:
<h3>Genrate Random Number Between two Integer</h3> <form method="POST"> <table> <tr> <td>Min Number</td> <td><input type="text" name="min" required/></td> </tr> <tr> <td>max Number</td> <td><input type="text" name="max" required/></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Genrate"/></td> </tr> </table> </form> <?php if(isset($_POST['submit'])){ $min=$_POST['min']; $max=$_POST['max']; if($min>$max){ echo 'Min Number can not be Greater Than max Number'; }else{ $random=mt_rand($min,$max); echo $random; } } ?>
php generate random number |
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.