Created
March 4, 2010 00:45
-
-
Save treed/321261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment