Skip to content

Commit

Permalink
Remove static _mostSignificantBit from UInt
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Jan 24, 2017
1 parent 1c6ef2e commit 0ddaf00
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/RandomKit/Extensions/Swift/Integer+RandomKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ extension Int8: UnsafeRandom, RandomWithMax, RandomWithMin, RandomToValue, Rando

extension UInt: UnsafeRandom, RandomWithMax, RandomWithMin, RandomToValue, RandomThroughValue, RandomWithinRange, RandomWithinClosedRange, RandomWithMaxWidth, RandomWithExactWidth {

private static let _mostSignificantBit: UInt = 1 << UInt((MemoryLayout<UInt>.size * 8) - 1)

/// Generates a random value of `Self` using `randomGenerator`.
public static func random<R: RandomGenerator>(using randomGenerator: inout R) -> UInt {
if MemoryLayout<Int>.size == 8 {
Expand All @@ -346,7 +344,13 @@ extension UInt: UnsafeRandom, RandomWithMax, RandomWithMin, RandomToValue, Rando
}

fileprivate var _resigned: UInt {
return self ^ ._mostSignificantBit
let msb: UInt
if MemoryLayout<Int>.size == 8 {
msb = 1 << 63
} else {
msb = 1 << 31
}
return self ^ msb
}

}
Expand Down

0 comments on commit 0ddaf00

Please sign in to comment.