Jump to content

myphptrip

New Members
  • Posts

    2
  • Joined

  • Last visited

myphptrip's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thank you! $TimeValue = floor(time() / 3600); // number of hours since Jan 1 1970 makes more sense, yeah. yeah it isn't that random - you can (obviously) calculate it. since there are 50 items in the array I am actually using, it shouldn't matter I guess. on the other hand: couldn't I just shuffle the array before itemcount kicks in?
  2. 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?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.