mt_strand

From: Date: Fri, 13 Feb 2004 10:37:47 +0000
Subject: mt_strand
Groups: php.general 
Request: Send a blank email to php-general+get-177585@lists.php.net to get a copy of this message
Hi All I could do with some pointers in using mt_strand. I understand that because my server has <PHP4.2.0 random number generators need to be seeded using mt_strand or mt_rand. I have the following code [created with the help of this list]: <?php $imgdir = /images/randomimages/"; if ($handle = opendir($imgdir)) { while (false !==($file = readdir($handle))) { if ($file != "." && $file != "..") { $random[] = $file; } } closedir($handle); } $image = $random[mt_rand(0, count($random)-1)]; ?> <?php include("/images/randomimages/$image"); ?> and have found the following in the PHP manual: <?php // seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } mt_srand(make_seed()); $randval = mt_rand(); ?> However - I'm not 100% sure how to incorporate it into my code - I have tried a few things but each time I break the code. Any help will be appreciated. Thanks Ange *********************************** Angela K Hilton Web & E-Learning Officer ISD, UMIST Tel: 0161 306 3109 ***********************************

« previous php.general (#177585) next »