note 60873 deleted from function.rand by nlopess
| From: | nlopess@php.net | Date: | Thu, 19 Jan 2006 11:53:12 +0000 |
| Subject: | note 60873 deleted from function.rand by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102086@lists.php.net to get a copy of this message | ||
Note Submitter: jessestat AT earthlink DOT net
----
On my server, I have a version of PHP that doesn't do random numbers.
However, I was able to create this system for viewing random photos, that works using time().
function makePhoto(){
global $pnum;
$pnum++;
include("photos/pdesc.php");
$t = time();
$t = str_split($t);
$t1 = $t[count($t)-1];
$t2 = $t[count($t)-2];
$t2 *= 10/count($pdesc);
$t2 = round($t2);
$t2 += $pnum;
if(isset($pdesc[$t2-1])){
$section = $pdesc[$t2-1];
$photo = $t2."/";
} else {
$section = $pdesc[0];
$photo = "1/";
}
$t1 *= 10/count($section);
$t1 = round($t1);
$t1 += $pnum;
if(isset($section[$t1-1])){
$photo .= $t1.".jpg";
} else {
$photo .= "1.jpg";
}
echo "<img src=\"photos/".$photo."\" width=\"70\"
height=\"70\">";
}
Getting random numbers is basically done by taking the time(), using str_split(), and then getting
one of the last digits. Then you have a random number.