title: Firestore: How to get random documents in a collection
body: <p>It is crucial for my application to be able to select multiple documents at random from a collection in firebase.</p>
  
  <p>Since there is no native function built in to Firebase (that I know of) to achieve a query that does just this, my first thought was to use query cursors to select a random start and end index provided that I have the number of documents in the collection.</p>
  
  <p>This approach would work but only in a limited fashion since every document would be served up in sequence with its neighboring documents every time; however, if I was able to select a document by its index in its parent collection I could achieve a random document query but the problem is I can't find any documentation that describes how you can do this or even if you can do this.</p>
  
  <p>Here's what I'd like to be able to do, consider the following firestore schema:</p>
  
  <pre><code>root/
    posts/
       docA
       docB
       docC
       docD
  </code></pre>
  
  <p>Then in my client (I'm in a Swift environment) I'd like to write a query that can do this:</p>
  
  <pre><code>db.collection("posts")[0, 1, 3] // would return: docA, docB, docD
  </code></pre>
  
  <p>Is there anyway I can do something along the lines of this? Or, is there a different way I can select random documents in a similar fashion?</p>
  
  <p>Please help.</p>