Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. class new_shoe:
  2.     def __init__(self):
  3.         # idx 0: number of 1s
  4.         # idx 1: number of 1s + number of 2s
  5.         # idx n: sum(number of 1s + ... + number of ns)
  6.         self.thresholds = [24,48,72,96,120,144,168,192,216]
  7.         self.maxCard = 312
  8.  
  9.     def rm_card(self, index):
  10.         self.maxCard = self.maxCard - 1
  11.         for i in range(index,9):
  12.             self.thresholds[i] = self.thresholds[i] - 1
  13.  
  14.     def getCard(self):
  15.         if (self.maxCard == 0):
  16.             return -1
  17.         # Generate a random number in the range [1,maxcard]
  18.         rand = random.randint(1,self.maxCard)
  19.  
  20.         # Determine the threshold array index corresponding to the random number
  21.         # If rand is in thresholds, the smallest index is returned.
  22.         # If rand is not in thresholds, the lar
  23.         index = bisect.bisect_left(self.thresholds, rand)
  24.  
  25.         self.rm_card(index)
  26.  
  27.         # The number is the index + 1
  28.         return index + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement