Data distribution by frequency

Greg Fortune gfortune_ewu at ispchannel.com
Sun Oct 8 15:16:25 EDT 2000


If I understand your code correctly, this isn't quite as picky as I'd like
it to be.  Rather than a random distribution that changes over time, I need
it to generate an identical list each time it is run and that list must be
in some kind of logical order.  For instance, the modem should be pinged
about every other minute and the gateway pinged every other minute offset by
one.  I'll try to get my idea into code a little later this afternoon, but
my lady thinks she is hungry so off I go for lunch ;)

Thanks,

Greg

Alex <the_brain at mit.edu> wrote in message
news:etdd7hcq8jo.fsf at x15-cruise-basselope.mit.edu...
>
> 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