Hello Angela,

Friday, February 13, 2004, 10:37:47 AM, you wrote:

AKH> However - I'm not 100% sure how to incorporate it into my code - I have
AKH> tried a few things but each time I break the code.

Your make_seed() function isn't going to work in this instance because
the important parts of it are outside of the function scope.

<?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();
?>

If you look carefully you'll see that all the function itself does is
return a unique value - the two commands that follow the function
(mt_srand and $randval=) use that result, but they're not part of the
function. So in essence just calling the function will never actually
work.

To get this to work in your code you would need to place the function
and mt_srand line somewhere at the start of your script.

Personally, it I think it'd be easier to do this which is a similar
approach but with a small re-write:

<?php

     function make_seed()
     {
              list($usec, $sec) = explode(' ', microtime());
              $seed = $sec + ($usec * 100000);
              mt_srand($seed);
     }

     // Call the rand seed function
     make_seed();
     
     $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)];

     include "/images/randomimages/$image";
?>

The above is un-tested but should work fine, just reply to this email
if it gives you a syntax error and I'll track it down.

-- 
Best regards,
 Richard                            mailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to