title: Creating random Bool in Swift
body: <p>I'm needing to create a random bool value in my game, in Swift.</p>
  
  <p>It's basically, if Yes (or 1), spawn one object, if No (or 0), spawn the other.</p>
  
  <p>So far, looking at <a href="https://stackoverflow.com/questions/24007129/how-does-one-generate-a-random-number-in-apples-swift-language">this question</a> and a similar one on here, I found this:</p>
  
  <pre><code>let randomSequenceNumber = Int(arc4random_uniform(2))
  </code></pre>
  
  <p>Now it works, but it seems bias to 0 to me... like ridiculously bias...</p>
  
  <p>This is how I'm then using the value:</p>
  
  <pre><code>if(randomSequenceNumber == 0)
      //spawn object A
  else
      //spawn object B
  </code></pre>
  
  <p>Is there a better way to implement this using a random bool value? That isn't bias to a certain value?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Bit of an experiment to see how many <code>1</code>'s vs <code>0</code>'s were were generated in 10,000 calls:</p>
  
  <pre><code>func experiment() {
      var numbers: [Int] = []
      var tester: Int = 0
      var sum = 0
  
      for i in 0...10000 {
          tester = Int(arc4random_uniform(2))
          numbers.append(tester)
          print(i)
      }
  
      for number in numbers {
          sum += number
      }
  
      print("Total 1's: ", sum)
  }
  
  Test 1: Console Output: Total 1's: 4936
  Test 2: Console Output: Total 1's: 4994
  Test 3: Console Output: Total 1's: 4995
  </code></pre>