Get random number (long)

Views: 7 Last modified: August 03rd, 2011 Comments: 0

This function will return an random generated number (Not a float).

<?php
function GetRandomNumber($min = false, $max = false)
{
	// Seed the generator
	mt_srand((double)microtime()*1000000);

	// Set the default min and max if no parameter has been passed
	if ($min === false)
		$min = 0;
	if ($max === false)
		$max = mt_getrandmax();

	// Return random between min and max
	return mt_rand($min, $max);
}
// Number between 0 and 2147483647
echo GetRandomNumber();

// Number between 5 and 10
echo GetRandomNumber(5, 10);

// Number between 0 and 100
echo GetRandomNumber(false, 100);
?>
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {5+8} =  
    Anything to add ?

        You must be logged in to post a comment.