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. @itemid=(...); %weight={id1 => weight1,...}; @weightspace=map {($_) x $weight{$_}} @itemid; $chosenid=$weightspace[int(rand()*scalar @weightspace)];