Random Images with no duplicates?

From: Date: Fri, 16 Dec 2005 04:35:37 +0000
Subject: Random Images with no duplicates?
Groups: php.general 
Request: Send a blank email to php-general+get-227514@lists.php.net to get a copy of this message
Hi, I'm still very green with PHP, but am working to fix that. I've searched high and low for an answer to this question and so far no solution has presented itself. I have a script to populate my web page with random images: <?php #random images example #this is your file $file = "images.txt"; #open the file $openFile = file($file); #generate a random number srand((double)microtime()*1000000); #get one of the entries in the file $random_image = $openFile[array_rand($openFile)]; #display the entry echo "<img src='$random_image' height='170' width='100'></img>"; ?> This works beautifully, but my problem is that sometimes, the same image displays twice or more on the same page-load. My page requires 10 different places where my images need to load, but I can't have any duplicate images show up. Any suggestions on what I need to modify here? Thanks in advance! Mike

« previous php.general (#227514) next »