update from Atlas with major reorg

This commit is contained in:
Luciano Ramalho
2015-04-17 21:29:30 -03:00
parent 57902d31b5
commit a786180239
134 changed files with 369 additions and 520 deletions

View File

@@ -1,3 +1,5 @@
# BEGIN LOTTERY_BLOWER
import random
from tombola import Tombola
@@ -6,19 +8,23 @@ from tombola import Tombola
class LotteryBlower(Tombola):
def __init__(self, iterable):
self.randomizer = random.SystemRandom() # <1>
self.clear()
self.load(iterable)
def clear(self):
self._balls = []
self._balls = list(iterable) # <1>
def load(self, iterable):
self._balls.extend(iterable)
self.randomizer.shuffle(self._balls) # <2>
def pick(self):
return self._balls.pop() # <3>
try:
position = random.randrange(len(self._balls)) # <2>
except ValueError:
raise LookupError('pick from empty BingoCage')
return self._balls.pop(position) # <3>
def loaded(self): # <4>
return len(self._balls) > 0
return bool(self._balls)
def inspect(self): # <5>
return tuple(sorted(self._balls))
# END LOTTERY_BLOWER