Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class new_shoe:
- def __init__(self):
- # idx 0: number of 1s
- # idx 1: number of 1s + number of 2s
- # idx n: sum(number of 1s + ... + number of ns)
- self.thresholds = [24,48,72,96,120,144,168,192,216]
- self.maxCard = 312
- def rm_card(self, index):
- self.maxCard = self.maxCard - 1
- for i in range(index,9):
- self.thresholds[i] = self.thresholds[i] - 1
- def getCard(self):
- if (self.maxCard == 0):
- return -1
- # Generate a random number in the range [1,maxcard]
- rand = random.randint(1,self.maxCard)
- # Determine the threshold array index corresponding to the random number
- # If rand is in thresholds, the smallest index is returned.
- # If rand is not in thresholds, the lar
- index = bisect.bisect_left(self.thresholds, rand)
- self.rm_card(index)
- # The number is the index + 1
- return index + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement