hi there, I'm using this function to get a random value from an array every new full hour.
function RandomQuoteByInterval($TimeBase, $QuotesArray){
// Make sure it is a integer
$TimeBase = intval($TimeBase);
// How many items are in the array?
$ItemCount = count($QuotesArray);
// By using the modulus operator we get a pseudo
// random index position that is between zero and the
// maximal value (ItemCount)
$RandomIndexPos = ($TimeBase % $ItemCount);
// Now return the random array element
return $QuotesArray[$RandomIndexPos];
it's initiated via something like this:
$DayOfTheYear = date('h');
// Example array with some random quotes
$RandomQuotes = array(
'No animals were harmed in the making of this snippet.',
'Nice snippets',
'The modulus operator rocks!',
'PHP is cool.'
);
print RandomQuoteByInterval($DayOfTheYear, $RandomQuotes);
Is my assumption correct that this will return the same value for let's say 3pm every day? because as far as I can read it, the randomness is defined only by the number of the hour.
If so, I am looking for a way that will change it. I don't want to return the same value that is returned on 3pm everyday. I want it to be random at the hour - but not constant across days.
I guess I could achieve it by adding day month and year value to the $RandomIndexPos?
$currentYear = date('Y');
$currentMonth = date('m');
$currentDay = date('d');
$RandomIndexPos = ($TimeBase % $ItemCount) + $currentYear +$currentMonth + $currentDay;
Would it work?