lundi 19 octobre 2015

Randomly picking numbers from a list according to a uniform distribution

I have a list as such

a = [.5,.57,.67,.8,1,1.33,2,4]

Which looks like this when plotted: enter image description here

I need to randomly pick a number in this list. In Python, I would normally go like this:

c = random.choice(a)

Except... Doing this biases the pick towards a lower value (the density is higher around 1 than it is around 4).

How would I go about picking a list entry according to a uniform distribution. As in c = random.random()*3.5+.5, but actually picking from the list?




Aucun commentaire:

Enregistrer un commentaire