title: Rails: get a specific number of random records
body: <p>So, my app has Photos that belong to Collections. I want to be able to show 13 photos from a specific collection on a page.</p>
  
  <p>I tried this:</p>
  
  <pre><code>c = Collection.first
  @photos = c.photos.offset(rand(c.photos.count)).limit(13)
  </code></pre>
  
  <p>This works, sort of. The problem is, if the collection doesn't have a lot more than 13 photos then it doesn't necessarily return 13 photos. I need to specifically get exactly 13 photos.</p>
  
  <p>FWIW In the case of my app a Collection is only created by admins/mods, so we can enforce that no collection will have fewer than 13 photos. What I need is to be able to start making the selection of photos random once more than 13 are available.</p>
  
  <p>How could I do this?</p>