     }
 }
 
+/**
+* generator:
+* new-value = (old-value * 16807) mod (2^31 - 1)
+*/
 extension ParkMillerRandom {
+    private func gen() -> UInt32 {
+        let value = UInt(internalSeed) * UInt(r1) % UInt(r0)
+        internalSeed = UInt32(value)
+        return internalSeed
+    }
+}
+
+extension ParkMillerRandom : GKRandom {
     /**
     Generates a random Int from entire spectrum.
     
     - returns: Int
     */
-    mutating func nextInt() -> Int {
+    func nextInt() -> Int {
         return Int(gen())
     }
     
     /**
-    Generates a random Int from entire spectrum.
+    Generates a random Int less than upperBound
     
-    - parameter min: minimum
-    - parameter max: maximum
+    - parameter upperBound: maximum
     
-    - returns: Int in range [min, max]
+    - returns: Int 
     */
-    mutating func nextInt(min min: Int, max: Int) -> Int {
-        let b = Float(min) - dif
-        let t = Float(max) + dif
-        return Int(round(b + ((t - b) * nextFloat())))
-    }
-    
-    /**
-    Generates a random Int bounded by the Range
-    
-    - parameter min: minimum
-    - parameter max: maximum
-    
-    - returns: Int in range [min, max]
-    */
-    mutating func nextInt(range: Range<Int>) -> Int {
-        if range.startIndex > range.endIndex {
-            return nextInt(min: range.endIndex, max: range.startIndex)
-        }
-        else {
-            return nextInt(min: range.startIndex, max: range.endIndex)
-        }
+    func nextIntWithUpperBound(upperBound: Int) -> Int {
+        let low = -dif
+        let high = Float(upperBound) + dif
+        return Int(low + ((high - low) * nextUniform()))
     }
     
     /**

//

import Foundation

private let r0:UInt32 = 2147483647
private let r1:UInt32 = 16807
private let dif:Float = 0.4999

struct ParkMillerRandom {
    /// Allow seeds between [1, 0X7FFFFFFE]
    private var internalSeed: UInt32 = 1
    var seed: UInt32 {

    
    - returns: Float [0,1]
    */
    func nextUniform() -> Float {
        return Float(gen()) / Float(r0)
    }
    
    /**
    Generates a random Bool
    
    - returns: true or false
    */
    func nextBool() -> Bool {
        let x = nextUniform()
        if x <= dif { return true }
        else { return false }
    }
}
