Presto-X Posted April 6, 2013 Share Posted April 6, 2013 Hey guys, I'm stumped, I'm trying to pull in a (as in 1) random image from a dir each time the page loads, I have that part down, but what I am having problems with is, if there are only 5 or so images in the folder, you have a 1 in 5 chance that the same image will get displayed twice. How can I keep this from happening? header("Content-type: image/jpeg"); $img = glob('images/*.{jpg,jpeg,png,gif}', GLOB_BRACE); $img = $img[array_rand($img)]; imagejpeg(imagecreatefromjpeg($img)); Link to comment https://forums.phpfreaks.com/topic/276597-stop-random-images-from-getting-displayed-twice/ Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 Put the images in an array and shuffle it, then store it in the session. Link to comment https://forums.phpfreaks.com/topic/276597-stop-random-images-from-getting-displayed-twice/#findComment-1423220 Share on other sites More sharing options...
TOA Posted April 6, 2013 Share Posted April 6, 2013 While I understand the desire for this, just to be a smart ass I feel I have to say: doesn't that defeat the purpose of random? Link to comment https://forums.phpfreaks.com/topic/276597-stop-random-images-from-getting-displayed-twice/#findComment-1423227 Share on other sites More sharing options...
Presto-X Posted April 6, 2013 Author Share Posted April 6, 2013 Thanks guys, I will give that a shot, thanks Jessica. TOA, yes, but it is less annoying to keep seeing the same image back to back Link to comment https://forums.phpfreaks.com/topic/276597-stop-random-images-from-getting-displayed-twice/#findComment-1423278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.