rand() method | How To Generate Random Number From 0 to 90 in PHP?

Date Published: 21/03/2020Published By: JaiSchool

PHP provides a function - rand() to generate the numbers randomly from one number to another number (ex:- 0 to 90).

rand() function has two parameters. The first parameter is for min number & the second is for max number. You get a random number from min to max in PHP. Separate parameter by comma ( , ).

rand() function example:-

<?php

$random_number = rand(0,90);

echo $random_number;

?>

Generate 5 digits random number - Simply pass min and max value in 5 digits in the first parameter.

<?php

$random_number = rand(10000,99999);

echo $random_number;

?>
Extra Reading
| Disable form submit action in PHP
| Array to String in PHP
| Print array
| Know string length in PHP
| Length of an array in PHP
| Change the class name in Javascript
| Know the current width of the window
| SQL select query
| Add a column in a table in SQL

Publish A Comment

Leave a Reply

Your email address will not be published.