echo mt_rand(10,100); // Output is 32
Syntax
int mt_rand ( int $min, int $max)
Parameter | DESCRIPTION |
---|---|
$min | Optional : Minimum range of random number to be generated. |
$max | Optional : Maximum range of random number to be generated. |
echo mt_rand();
Out put is ( will chage )
2147483647
mt_srand(100);
echo mt_rand(1, 100); // Output: 52
echo mt_rand(1, 100); // Output: 5
$min = 0;
$max = 1;
echo $min + (mt_rand() / mt_getrandmax()) * ($max - $min); // Output: Random float between 0 and 1
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$password = '';
for ($i = 0; $i < 8; $i++) {
$password .= $characters[mt_rand(0, strlen($characters) - 1)];
}
echo $password; // Output: Random 8-character password
$red = mt_rand(0, 255);
$green = mt_rand(0, 255);
$blue = mt_rand(0, 255);
echo sprintf("#%02x%02x%02x", $red, $green, $blue); // Output: Random hex color
$arr = [1, 2, 3, 4, 5];
shuffle($arr);
print_r($arr); // Output: Array elements in random order
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.