title: How to get random element from a set in Swift?
body: <p>As of Swift 1.2, Apple introduces <code>Set</code> collection type.</p>
  
  <p>Say, I have a set like:</p>
  
  <pre><code>var set = Set&lt;Int&gt;(arrayLiteral: 1, 2, 3, 4, 5)
  </code></pre>
  
  <p>Now I want to get a random element out of it.  Question is how?  <code>Set</code> does not provide <code>subscript(Int)</code> like <code>Array</code> does.  Instead it has <code>subscript(SetIndex&lt;T&gt;)</code>.  But firstly, <code>SetIndex&lt;T&gt;</code> does not have accessible initializers (hence, I can not just create an index with the offset I need), and secondly even if I can get the index for a first element in a set (<code>var startIndex = set.startIndex</code>) then the only way I can get to the N-th index is through consecutive calls to <code>successor()</code>.</p>
  
  <p>Therefore, I can see only 2 options at the moment, both ugly and expensive:</p>
  
  <ul>
  <li>Convert the set into array (<code>var array = [Int](set)</code>) and use its subscript (which perfectly accepts <code>Int</code>); or</li>
  <li>Get index of a first element in a set, traverse the chain of <code>successor()</code> methods to get to the N-th index, and then read corresponding element via set's subscript.</li>
  </ul>
  
  <p>Do I miss some other way?</p>