title: How do you generate a random number in swift?
body: <p><strong>tl:dr; How do I generate a random number, because the method in the book picks the same numbers every time.</strong></p>
  
  <p>This seems to be the way in Swift to generate a random number, based on the book released from Apple.  </p>
  
  <pre><code>protocol RandomNumberGenerator {
      func random() -&gt; Double
  }
  class LinearCongruentialGenerator: RandomNumberGenerator {
      var lastRandom = 42.0
      let m = 139968.0
      let a = 3877.0
      let c = 29573.0
      func random() -&gt; Double {
          lastRandom = ((lastRandom * a + c) % m)
          return lastRandom / m
      }
  }
  let generator = LinearCongruentialGenerator()
  
  for _ in 1..10 {
      // Generate "random" number from 1-10
      println(Int(generator.random() * 10)+1)
  }
  </code></pre>
  
  <p>The problem is that in that for loop I put at the bottom, the output looks like this:</p>
  
  <pre><code>4
  8
  7
  8
  6
  2
  6
  4
  1
  </code></pre>
  
  <p>The output is the same every time, no matter how many times I run it.</p>