Data distribution by frequency
Alex
the_brain at mit.edu
Sun Oct 8 00:08:27 EDT 2000
In this context 'probability density function' just refers to the
likelihood that one of your finite set of options is chosen in some
random process. Here's something that does roughly what you want, for
instance. It may send out more than one ping at a time, but the average
traffic it generates will be about right:
import random
class Choices:
def __init__(self, events, counts):
assert len(events) == len(counts)
self.total = 0.
for count in counts:
self.total = self.total + count
self.events = events
self.likelihoods = []
for count in counts:
self.likelihoods.append(count/self.total)
def generate_events(self):
current_events = []
for event, likelihood in map(None,
self.events,
self.likelihoods):
if likelihood >= random.random():
current_events.append(event)
retun current_events
--
Speak softly but carry a big carrot.
More information about the Python-list
mailing list