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)); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
TOA Posted April 6, 2013 Share Posted April 6, 2013 (edited) 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? Edited April 6, 2013 by TOA Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.