title: URL to a random image
body: <p>I want to make something that I've not seen done in web development, but it seems possible. <strong>I want a URL that can be put into any arbitrary HTML <code>&lt;IMG/&gt;</code> tag or CSS <code>background-image</code> property that, when accessed, <em>is</em> a random image.</strong> I don't want the page to point or redirect to a random image, and I don't want it to display or embed a random image, as these things won't work with the above-stated requirements. I've seen solutions for displaying a random image in a webpage using Javascript to swap a property or hide an element, but this has to make the <em>entire page</em> the image, with no preceding or succeeding binary or ASCII data. I want it to be usable by people who don't know anything about programming. What I'm aiming for is something like this:</p>
  
  <pre><code>http://example.com/randomImage/
  </code></pre>
  
  <p>In theory, every time a page is loaded with this URL in the CSS or HTML, a random image will be displayed in the referenced element. It should work so that if you have several <code>&lt;IMG/&gt;</code> elements or several elements with their <code>background-image</code> referencing this page, they should all show randomly different images.</p>
  
  <p>My first thought is to use PHP (in the structure described below) to look into a particular directory, pick an image file at random, and echo its binary data. <strong>If this is possible, then how would I go about doing it? If not, then does anyone have any other ideas?</strong></p>
  
  <p>My primary idea as pseudocode:</p>
  
  <pre><code>&lt;?PHP
  $chosenImage = getRandomFileFrom("./rand/");
  $bytes = readFileAsBinary($chosenImage);
  foreach($bytes as $byte){
      echo $byte;
  }
  ?&gt;
  </code></pre>
  
  <p><em>I don't care about true or pseudo-random. It could cycle each time for all I care; all I require in this endeavor is that multiple images can be referenced as a single URL</em></p>