mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Issue #19169: Micro refactoring with a micro benefit for brevity and speed.
This commit is contained in:
		
							parent
							
								
									facd0a346f
								
							
						
					
					
						commit
						f77cdbeff7
					
				
					 1 changed files with 2 additions and 2 deletions
				
			
		|  | @ -220,10 +220,11 @@ def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type, | ||||||
|                    Method=_MethodType, BuiltinMethod=_BuiltinMethodType): |                    Method=_MethodType, BuiltinMethod=_BuiltinMethodType): | ||||||
|         "Return a random int in the range [0,n).  Raises ValueError if n==0." |         "Return a random int in the range [0,n).  Raises ValueError if n==0." | ||||||
| 
 | 
 | ||||||
|  |         random = self.random | ||||||
|         getrandbits = self.getrandbits |         getrandbits = self.getrandbits | ||||||
|         # Only call self.getrandbits if the original random() builtin method |         # Only call self.getrandbits if the original random() builtin method | ||||||
|         # has not been overridden or if a new getrandbits() was supplied. |         # has not been overridden or if a new getrandbits() was supplied. | ||||||
|         if type(self.random) is BuiltinMethod or type(getrandbits) is Method: |         if type(random) is BuiltinMethod or type(getrandbits) is Method: | ||||||
|             k = n.bit_length()  # don't use (n-1) here because n can be 1 |             k = n.bit_length()  # don't use (n-1) here because n can be 1 | ||||||
|             r = getrandbits(k)          # 0 <= r < 2**k |             r = getrandbits(k)          # 0 <= r < 2**k | ||||||
|             while r >= n: |             while r >= n: | ||||||
|  | @ -231,7 +232,6 @@ def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type, | ||||||
|             return r |             return r | ||||||
|         # There's an overriden random() method but no new getrandbits() method, |         # There's an overriden random() method but no new getrandbits() method, | ||||||
|         # so we can only use random() from here. |         # so we can only use random() from here. | ||||||
|         random = self.random |  | ||||||
|         if n >= maxsize: |         if n >= maxsize: | ||||||
|             _warn("Underlying random() generator does not supply \n" |             _warn("Underlying random() generator does not supply \n" | ||||||
|                 "enough bits to choose from a population range this large.\n" |                 "enough bits to choose from a population range this large.\n" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger