Without using cookies or session information, you're going to go through your 
picture list faster depending on how many users are accessing the random pic 
page.  If you don't make it user-specific, then it doesn't really matter if you 
go through the images sequentially.. it may appear random on the user end 
because other users are going to be grabbing sequential pics as well.

If you want to stir the waters a bit, you could run them sequentially but 
randomize the sequence.  This is what some music playlist programs do when you 
randomize a playlist.  Instead of pulling a random song from the list and 
risking playing the same song back to back, it just shuffles the playlist and 
plays it sequentially.  When you get to the end of your randomized list, you 
can re-shuffle it and start over.  This gives some semblance of randomness.

If you want to make sure each image gets its fair amount of time in the 
spotlight,  you could keep track of how many times each image has been 
displayed.  Having a database table with a list of all the image names and 
their 'served' count would let you weight your list a bit to give preference to 
the images that havn't been displayed that often.


And if you want to give each user the total package, you can keep track of how 
many times each image was served to a specific user and weight your shuffling 
that way.


I'm sure there are other ways, but there are just a few that may be viable for 
you, depending on the level of randomness per user you need.

Let us know what solution you come up with.  I'm sure others have had similar 
questions and just havn't asked.

-TG

= = = Original message = = =

Hi there!

I have created a script the generates random pictures...

<?php
//Random pictures
//
$pictures[0] = "bil1.gif";
$pictures[1] = "bil2.gif";
$pictures[2] = "bil3.gif";
$pictures[3] = "bil4.gif";


for ($i=0;$i<3;$i++) 
  $r = rand(0,3);
?>
<p>&nbsp;&nbsp;<img src="<?php echo $pictures[$r];?>"></p>
<?php


?>


With this above script the same picture can be shown twice. Is there any 
smart way of avoiding this without having to rely on cookies/sessionids?

Best regards
/Gustav Wiberg
Stammis Internet - http://www.stammis.com/ - pedigrees on the net



___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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

Reply via email to