 //
 
 import Foundation
+import GameplayKit
 
 private let r0:UInt32 = 2147483647
 private let r1:UInt32 = 16807
 private let dif:Float = 0.4999
 
-struct ParkMillerRandom {
+@objc class ParkMillerRandom : NSObject {
     /// Allow seeds between [1, 0X7FFFFFFE]
     private var internalSeed: UInt32 = 1
     var seed: UInt32 {

    
    - returns: Float [0,1]
    */
    mutating func nextFloat() -> Float {
        return (Float(gen()) / Float(r0))
    }
    
    /**
    Generates a random Float from entire spectrum.
    
    - parameter min: minimum
    - parameter max: maximum
    
    - returns: Float in range [min, max]
    */
    mutating func nextFloat(min min: Float, max: Float) -> Float {
        return (min + ((max - min) * nextFloat()))
    }
    
    /**
    Generates a random Float bounded by the Range
    
    - parameter min: minimum
    - parameter max: maximum
    
    - returns: Float in range [min, max]
    */
    mutating func nextFloat(range: Range<Int>) -> Float {
        if range.startIndex > range.endIndex {
            return nextFloat(min: Float(range.endIndex), max: Float(range.startIndex))
        }
        else {
            return nextFloat(min: Float(range.startIndex), max: Float(range.endIndex))
        }
    }
}

/**
* generator:
* new-value = (old-value * 16807) mod (2^31 - 1)
*/
extension ParkMillerRandom {
    private mutating func gen() -> UInt32 {
        let value = UInt(internalSeed) * UInt(r1) % UInt(r0)
        internalSeed = UInt32(value)
        return internalSeed
    }
}


    }
}

/**
* 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
    */
    func nextInt() -> Int {
        return Int(gen())
    }
    
    /**
    Generates a random Int less than upperBound
    
    - parameter upperBound: maximum
    
    - returns: Int 
    */
    func nextIntWithUpperBound(upperBound: Int) -> Int {
        let low = -dif
        let high = Float(upperBound) + dif
        return Int(low + ((high - low) * nextUniform()))
    }
    
    /**
