php3-list | 199901
Date: 01/31/99
- Next message: Nola Fuller: "[PHP3] Delete"
- Previous message: Peter van Dijk: "Re: [PHP3] strange problem with rand()"
- Maybe in reply to: Hans Westerbeek: "[PHP3] strange problem with rand()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>I am using PHP on FreeBSD (i am a Pair networks client)
>and i have a strange problem, look at this:
>
>$images = array("batman","indian","mermaid");
>/* images array made shorter, doesn't seem to make a difference to me */
>$count = count($images);
>srand((double)microtime()*1000000); //seeding the random generator
>$i=rand(0,$count); //picking a value between 0 and the length of $images
This code works fine on a machine that I use with Free BSD and PHP v3.05.
If you read the change log, you will see that rand() was improved for some
machines in PHP 3.06. You might like to see if upgrading solves your
problem.
Your code has one problem though, you are getting a random index between 0
and $count. You want one between 0 and $count-1
Cheers,
Luke
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>
- Next message: Nola Fuller: "[PHP3] Delete"
- Previous message: Peter van Dijk: "Re: [PHP3] strange problem with rand()"
- Maybe in reply to: Hans Westerbeek: "[PHP3] strange problem with rand()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

