m_al has asked for the wisdom of the Perl Monks concerning the following question:
How can I pick a random element, using the values as weights? I'm going for a more generic solution than applies to this specific hash type, since currently I actually have a matrix like{ a => 0.1, b => 0.5, c => 0.4, }
(but I'm going to change it because it's crazy). TIA al[ [a, 0.1], [b, 0.5] ... ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I get a random index with weighting?
by kyle (Abbot) on Nov 24, 2008 at 21:55 UTC | |
|
Re: How do I get a random index with weighting?
by JavaFan (Canon) on Nov 24, 2008 at 23:20 UTC | |
|
Re: How do I get a random index with weighting?
by bart (Canon) on Nov 24, 2008 at 23:35 UTC | |
|
Re: How do I get a random index with weighting?
by perreal (Monk) on Nov 25, 2008 at 00:00 UTC | |
by gone2015 (Deacon) on Nov 25, 2008 at 01:03 UTC | |
|
Re: How do I get a random index with weighting?
by salva (Canon) on Nov 25, 2008 at 09:34 UTC | |
by m_al (Novice) on Nov 25, 2008 at 11:54 UTC |