Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Neat. I've always been interested in weighted probabilities.

    I have a system I've used for lots of things where you select from a list where items near the top are more heavily weighted than items near the bottom. After selection, the selected item goes to the bottom of the list for the next round, meaning items that have not been recently selected are more likely to be picked sooner. Basically it's a way of randomly shuffling but giving precedence to trying not to repeat things too soon.

    This started out implementation as a stack of CD's I used to cycle through to listen to at work: pick a CD, then put it at the bottom and randomly pick another but weight it so I'd tend to hear something I hadn't heard in a while. Today it's implemented as a private Perl module that works on an array, and in fact I had a program that implemented this through Tie::File so that I could run it on a text file containing all my choices and the file would keep track of the ordering from run to run.

    The mathematics is that the item at the bottom of the list has probability 1 out of T of being selected, the next item up has probability 2 out of T of being selected, next item has probability 3 out of T, etc., all the way to the top of the list, item N, which has probability N out of T of being selected. T = SUM(1..N). T is a triangular number [wikipedia.org], hence the term "triangular probabilities."

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers