mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 10:59:39 +00:00 
			
		
		
		
	simpler range mask calculation
This commit is contained in:
		@ -65,21 +65,9 @@ public extension RandomProvider where Output: UnsignedInteger {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mutating func nextModless(in bound: Output) -> Output {
 | 
					  mutating func nextModless(in bound: Output) -> Output {
 | 
				
			||||||
    func pow2MaskFrom(range num: Output) -> Output {
 | 
					    let shift = bound.leadingZeroBitCount
 | 
				
			||||||
      if num & (num - 1) == 0 {
 | 
					    let mask = Output.max &>> shift
 | 
				
			||||||
        return num - 1
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      var result: Output = 1
 | 
					 | 
				
			||||||
      for _ in 0..<Output.bitWidth {
 | 
					 | 
				
			||||||
        if result >= num {
 | 
					 | 
				
			||||||
          return result - 1
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        result <<= 1
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      return .max
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mask = pow2MaskFrom(range: bound)
 | 
					 | 
				
			||||||
    var result: Output
 | 
					    var result: Output
 | 
				
			||||||
    repeat {
 | 
					    repeat {
 | 
				
			||||||
      result = next() & mask
 | 
					      result = next() & mask
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user