----- Original Message -----
From: "Chris Pine" <nemo / hellotree.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Friday, April 18, 2003 3:33 PM
Subject: Re: Biased weighted random?


> All right...
>
> It's not pretty, but it works and you only have to do it once, right at
the
> beginning of your endless random shuffle thing.
>
> The idea is to use the "bonehead" algorithm, but not with your target
> probabilities as the weights, since that won't work.
>
> Instead, use this program.  Enter in your weights into the `weights' array
> (inside the call to `normalize' and run it.
>
> Take the new weights to use (the first bunch of numbers) and put them into
> your "bonehead" algorithm as the weights (assuming the probabilities shown
> (second bunch of numbers) is close enough for you... if not, change the
`50'
> in `50.times' to something bigger).

[snip fascinating code]

1. Are you sure you want to call Daniel's method
the bonehead algorithm? :)

2. This reminds me so much of when I studied
mathematical models of population genetics. (It
was my first real exposure to matrices... I had
discrete math and calculus, but never linear
algebra.)

3. As I did back then, I can't help wondering:
Shouldn't there be a simple non-iterative solution
for this? Or at least non-matrix? Something like,
umm, find the geometric mean and divide each weight
by that and multiply by the price of tea in China?

Hal