Biased random?

Jon Clements joncle at googlemail.com
Mon Aug 27 17:17:31 EDT 2007


How about decorating your list of elements with an additional value,
which indicates the weight of that element. A value of 1 will indicate
'as likely as any other', < 1 will be 'less likely than' any other and
> 1 will be 'more likely than any other'. Then create a sorted list
based on the combined value of weight and the output of random(); from
this take the first N many elements to meet your requirements.

hth

Jon




On 27 Aug, 21:42, Ivan Voras <ivoras at __fer.hr__> wrote:
> Hi,
>
> I have a list of items, and need to choose several elements from it,
> "almost random". The catch is that the elements from the beginning
> should have more chance of being selected than those at the end (how
> much more? I don't care how the "envelope" of probability looks like at
> this point - can be linear). I see that there are several functions in
> Python standard libraries for various distribution, but is there an easy
> pythonic way to make them do what I need?
>
>  signature.asc
> 1KDownload





More information about the Python-list mailing list