title: Determine best cdn for image and remember it
body: <p>I want a way to take any input (url) and get back a number between 1-4, distributed as even as possible 25% for any input. It's important that it gets the same value of 1-4 every time.</p>
  
  <p>The reason I want this is so that I can create seemingly random and evenly disturbed content for a set of CNAMEs (subdomains) for a CDN. It would take pictures that were originally <code>www.website.com/picture.png</code> and output them as </p>
  
  <p><code>cdn1.website.com/picture.png</code> or 
  <code>cdn2.website.com/picture.png</code> or 
  <code>cdn3.website.com/picture.png</code> or 
  <code>cdn4.website.com/picture.png</code> </p>
  
  <p>Effectively allowing me to bypass the browser restrictions set to a subdomain, giving me more parallel connections (Read more: <a href="http://yuiblog.com/blog/2007/04/11/performance-research-part-4/" rel="nofollow">http://yuiblog.com/blog/2007/04/11/performance-research-part-4/</a>). The reason why I want the URL to <strong>always</strong> pass back to a specific CDN  is for caching purposes; If the <code>www.website.com/picture.png</code> is first displayed as <code>cdn1.website.com/picture.png</code> and a second time around as <code>cdn2.website.com/picture.png</code> then the browser would not know that it has the same picture cached already under cdn1 and would download the same picture twice, rather than relying on cache.</p>
  
  <p><hr>
  Here the suggested php at it, but I as you can see from results that I don't get that 25% ratio I would like for small sample set. I am looking for alternatives that would also be somewhat close to 25% distribution for small samples.</p>
  
  <pre><code>&lt;?php
  
  $num_array = array();
  for ($i = 1; $i &lt;= 10000; $i++) {
      $num_array[]=(crc32(genRandomURL()) % 4)+1;
  }
  
  
  print "&lt;pre&gt;";
  print_r(array_count_values($num_array));
  print "&lt;/pre&gt;";
  
  $num_array = array();
  for ($i = 1; $i &lt;= 10; $i++) {
      $num_array[]=(crc32(genRandomURL()) % 4)+1;
  }
  
  
  print "&lt;pre&gt;";
  print_r(array_count_values($num_array));
  print "&lt;/pre&gt;";
  
  
  function genRandomURL($length = 10) {
      $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
      $string = "";
      for ($p = 0; $p &lt; $length; $p++) {
          $string .= $characters[mt_rand(0, strlen($characters))];
      }
  
      return "http://www.website.com/dir/dir2/dir3/".$string.".png";
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>Array
  (
      [3] =&gt; 2489
      [1] =&gt; 2503
      [2] =&gt; 2552
      [4] =&gt; 2456
  )
  Array
  (
      [1] =&gt; 5
      [2] =&gt; 1
      [3] =&gt; 3
      [4] =&gt; 1
  )
  </code></pre>