 /// - Parameter range: Range random value.
 /// - Returns: Returns the created random integer.
 public func randomInt(range: ClosedRange<Int>) -> Int {
-    var offset = 0
-    
-    if range.lowerBound < 0 {
-        offset = abs(range.lowerBound)
-    }
-    
-    let min = UInt32(range.lowerBound + offset)
-    let max = UInt32(range.upperBound + offset)
-    
-    #if os(Linux)
-        return Int(Int(min) + Int(abs(Int.random())) % Int(max - min)) - offset
-    #else
-        return Int(min + arc4random_uniform(max - min)) - offset
-    #endif
+    return Int(randomFloat(range: Float(range.lowerBound)...Float(range.upperBound)))
 }
 
 /// Create a random float between the given range.

///   - maxValue: Maxinum random value. Default is 1.
/// - Returns: Returns the created random float.
public func randomFloat(min minValue: Float = 0, max maxValue: Float = 1) -> Float {
    #if os(Linux)
        let random = abs(Float.random())
    #else
        let random = Float(arc4random()) / Float(UINT32_MAX)
    #endif
    return random * abs(minValue - maxValue) + min(minValue, maxValue)
}

// MARK: - Randomizer struct

#if os(Linux)
    /// Produces great cryptographically random numbers.
    private struct Randomizer {
        /// /dev/urandom file.
        static let file = fopen("/dev/urandom", "r")!
        /// Random queue.
        static let queue = DispatchQueue(label: "random")
        
        /// Get a random number of a given capacity.
        ///
        /// - Parameter count: Byte count.

            _ = queue.sync {
                fgets(data, Int32(capacity), file)
            }
    
            return Array(UnsafeMutableBufferPointer(start: data, count: count))
        }
    #else
        /// Get a random number of a given capacity.
        ///
        /// - Parameter count: Byte count.
        /// - Returns: Return the random number.
        static func get(count: Int) -> [UInt8] {
            let capacity = count + 1
            var data = UnsafeMutablePointer<UInt8>.allocate(capacity: capacity)
            var secure: Int32 = 0
            defer {
                data.deallocate(capacity: capacity)
            }
            _ = queue.sync {
                secure = SecRandomCopyBytes(kSecRandomDefault, capacity, data)
            }
            
            return secure == 0 ? Array(UnsafeMutableBufferPointer(start: data, count: count)) : [0]
        }
    #endif
}

// MARK: - Extensions

/// This extension adds some useful function to Integer.
public extension Integer {
    /// Creates a random integer number.
    ///
    /// - Returns: Returns the creates a random integer number.
    static func random() -> Self {
        let numbers = Randomizer.get(count: MemoryLayout<Self>.size)
        return numbers.withUnsafeBufferPointer { bufferPointer in
            return bufferPointer.baseAddress!.withMemoryRebound(to: Self.self, capacity: 1) {
                return $0.pointee
            }
        }
    }
}

/// This extesion adds some useful functions to Double.
public extension Double {
