mercredi 15 janvier 2020

What is the difference between the random.choices() and random.sample() functions?

I have the following list: list = [1,1,2,2].

After applying the sample method (rd.sample(list, 3)) the, output is [1, 1, 2].

After applying the choices method (rd.choices(list, 3)), the output is: [2, 1, 2].

What is the difference between these two methods? When should one be preferred over the other?




Aucun commentaire:

Enregistrer un commentaire