Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Knuths-algorithm-S/Python/knuths-algorithm-s-2.py
Normal file
16
Task/Knuths-algorithm-S/Python/knuths-algorithm-s-2.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class S_of_n_creator():
|
||||
def __init__(self, n):
|
||||
self.n = n
|
||||
self.i = 0
|
||||
self.sample = []
|
||||
|
||||
def __call__(self, item):
|
||||
self.i += 1
|
||||
n, i, sample = self.n, self.i, self.sample
|
||||
if i <= n:
|
||||
# Keep first n items
|
||||
sample.append(item)
|
||||
elif randrange(i) < n:
|
||||
# Keep item
|
||||
sample[randrange(n)] = item
|
||||
return sample
|
||||
Loading…
Add table
Add a link
Reference in a new issue