How to generate fixed length random number in php?

Today I will tell you how you can generate fixed random number Using PHP? First of all, you create an PHP file, add codes. Then run codes on the server show results.you can use rand() function for that in PHP.

Best Keywords : generate fixed length random number in PHP, Generate a random number with pre-defined length PHP,PHP random x digit number PHP, generate fixed length random number in PHP code example

Example:

<?php
function generateRandomString($length = 25) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
//usage 
$myRandomString = generateRandomString(5);
?>


Generate random numbers between 1 to 100

<?php
echo rand(1,100);
?>