How to retrieve a row, biased by populatity?

Daniel Perrett perrettdl at
Tue Aug 21 21:49:50 BST 2012

Sort them by metric and then select the row n where n is a biased
random number between 0 and 1 mutliplied by the number of records and

The question is then how to generate 'n' and that depends on what you
mean by 'biased'. You need to create a function which maps equally
distributed random numbers between 0 and 1 to numbers distributed in
the way you want, which could be something like n = 1 - rand()^2.


On 21 August 2012 21:22, Dave Hodgkinson <davehodg at> wrote:
> Possibly a perl question. SQL would do...
> 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?

More information about the mailing list