Guest User

Untitled

a guest
May 20th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def handle_random(self, target, args):
  2. index = -1
  3. total_weight = 0
  4. current_time = time.time()
  5. for ttime in self.times:
  6. total_weight += math.log(current_time - ttime)
  7. r = self.rnd.random() * total_weight
  8. for n in range(len(self.quotes)):
  9. if index == -1:
  10. weight = math.log(current_time - self.times[n])
  11. #print self.quotes[n] + " is " + str(weight)
  12. if (r < weight):
  13. index, outbound = n, self.quotes[n]
  14. else:
  15. r -= weight
  16. if index == -1:
  17. index, outbound = len(self.quotes)-1, self.quotes[len(self.quotes)-1]
  18. self.message(target, _("[Qu-Random:") + str(index) + "] " + outbound)
  19. self.times[index] = time.time()
  20. if self.timing != 0:
  21. print _(" |--- Random handled in ") + str(time.time() - self.timing)
Add Comment
Please, Sign In to add comment