mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Add comments regarding speed/space/entropy trade-offs (GH-10885)
This commit is contained in:
		
							parent
							
								
									1747334794
								
							
						
					
					
						commit
						7fc633f5a5
					
				
					 1 changed files with 13 additions and 0 deletions
				
			
		|  | @ -333,6 +333,19 @@ def sample(self, population, k): | ||||||
|         # preferred since the list takes less space than the |         # preferred since the list takes less space than the | ||||||
|         # set and it doesn't suffer from frequent reselections. |         # set and it doesn't suffer from frequent reselections. | ||||||
| 
 | 
 | ||||||
|  |         # The number of calls to _randbelow() is kept at or near k, the | ||||||
|  |         # theoretical minimum.  This is important because running time | ||||||
|  |         # is dominated by _randbelow() and because it extracts the | ||||||
|  |         # least entropy from the underlying random number generators. | ||||||
|  | 
 | ||||||
|  |         # Memory requirements are kept to the smaller of a k-length | ||||||
|  |         # set or an n-length list. | ||||||
|  | 
 | ||||||
|  |         # There are other sampling algorithms that do not require | ||||||
|  |         # auxiliary memory, but they were rejected because they made | ||||||
|  |         # too many calls to _randbelow(), making them slower and | ||||||
|  |         # causing them to eat more entropy than necessary. | ||||||
|  | 
 | ||||||
|         if isinstance(population, _Set): |         if isinstance(population, _Set): | ||||||
|             population = tuple(population) |             population = tuple(population) | ||||||
|         if not isinstance(population, _Sequence): |         if not isinstance(population, _Sequence): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger