Create random numbers

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

This snippet will return a string containing random numbers. It takes 1 parameter which should be an integer. This will be the length of your string. If the parameter is not an integer, it will return false!

Example of use:

echo create_random_numbers(5);
function create_random_numbers($length)
{
	if (!is_int($length)) return false;

	mt_srand((double)microtime()*1000000);

	$random = '';

	for ($a = 0; $a < $length; $a++)
	{
		$random .= mt_rand(0, 9);
	}

	return $random;
}
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
    Bluehost

    Mail this!

    To: From:Sum {1+9} =  
    Anything to add ?

        You must be logged in to post a comment.