mardi 24 octobre 2017

Randomly generate integers with a distribution that prefers low ones

I have an list ordered by some quality function from which I'd like to take elements, preferring the good elements at the beginning of the list.

Currently, my function to generate the random indices looks essentially as follows:

def pick():
    p = 0.2
    for i in itertools.count():
        if random.random() < p:
            break
    return i

It does a good job, but I wonder:

  1. What's the name of the generated random distribution?
  2. Is there a built-in function in Python for that distribution?



Aucun commentaire:

Enregistrer un commentaire