How to retrieve a row, biased by populatity?

Roger Burton West roger at
Tue Aug 21 21:38:45 BST 2012

On Tue, Aug 21, 2012 at 09:22:42PM +0100, Dave Hodgkinson wrote:
>Given a set of data, say bands, with each having a ranking, either a
>review metric or a sales ranking, how would you retrieve a random
>row, but biased towards the higher ranking?

Broadly: convert each ranking into a weight (larger number = "better"
item), then index randomly into the weight space.

%weight={id1 => weight1,...};
@weightspace=map {($_) x $weight{$_}} @itemid;
$chosenid=$weightspace[int(rand()*scalar @weightspace)];

More information about the mailing list