#native_company# #native_desc#
#native_cta#

Random Number by Hour, Day, Month

By Ryan Humphries
on August 10, 2002

Version: 1.0

Type: Function

Category: Math Functions

License: GNU General Public License

Description: Generates a random number based on the current hour, day, or month. It does this by seeding the srand with a specific number for each. Usage then remains the same as with any other random. Includes the seeding for the most random number php offers.

function seed_random ($how = 'total')
{
	switch ($how)
	{
		
		case hour: // Sets A Random Number For The Hour

			$time = time();
			$today = mktime(0, 0, (int)date("H", $time), (int)date("n", $time),(int)date("j", $time), (int)date("Y", $time));     
			// N.B. pi makes the script more random so as not to repeat numbers from time to time
			srand($today / pi());
			break;

		case day: // Sets A Random Number For The Day
	
			$time = time();
			$today = mktime(0, 0, 0, (int)date("n", $time),(int)date("j", $time), (int)date("Y", $time));     
			srand($today / pi());
			break;

		case month: // Sets A Random Number For The Month
	
			$time = time();
			$today = mktime(0, 0, 0, 0,(int)date("j", $time), (int)date("Y", $time));     
			srand($today / pi());
			break;
		
		default: // Sets a Truly Random Number Based On The Milisecond
	
			srand((double)microtime()*1000000);
			break;

	} // Close The Switch Control
} // Close The Function

// Actual Call To Random Remains The Same In All Cases
$some_var = rand (int min, int max);