note 48424 added to function.srand

From: Date: Thu, 23 Dec 2004 09:39:48 +0000
Subject: note 48424 added to function.srand
Groups: php.notes 
Request: Send a blank email to php-notes+get-82198@lists.php.net to get a copy of this message
Another use of srand is to obtain the same value of rand in a determined time interval. Example: you have an array of 100 elements and you need to obtain a random item every day but not to change in the 24h period (just imagine "Today's Photo" or similar). <?php $seed = floor(time()/86400); srand($seed); $item = $examplearray[rand(0,99)]; ?> You obtain the same value every time you load the page all the 24h period. ---- Manual Page -- http://www.php.net/manual/en/function.srand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48424 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48424&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48424&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82198) next »