Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def handle_random(self, target, args):
- index = -1
- total_weight = 0
- current_time = time.time()
- for ttime in self.times:
- total_weight += math.log(current_time - ttime)
- r = self.rnd.random() * total_weight
- for n in range(len(self.quotes)):
- if index == -1:
- weight = math.log(current_time - self.times[n])
- #print self.quotes[n] + " is " + str(weight)
- if (r < weight):
- index, outbound = n, self.quotes[n]
- else:
- r -= weight
- if index == -1:
- index, outbound = len(self.quotes)-1, self.quotes[len(self.quotes)-1]
- self.message(target, _("[Qu-Random:") + str(index) + "] " + outbound)
- self.times[index] = time.time()
- if self.timing != 0:
- print _(" |--- Random handled in ") + str(time.time() - self.timing)
Add Comment
Please, Sign In to add comment