random.sample

The random.sample function returns a list of k elements extracted without repetition of the sequence population. That is, it returns a sample of that sequence. If population contains repeated elements, each of them can be chosen separately as part of the sample.

Submitted by admin on Thu, 03/11/2021 - 21:24

random.choices

The random.choices function returns a list of k randomly drawn elements with replacement of the sequence population.

By default, the probability of each element in population of being extracted is the same, but it can be modified in two ways:

Submitted by admin on Thu, 03/11/2021 - 17:26

random.choice

The random.choice function returns a random value extracted from the sequence passed as an argument. If this sequence is empty, the function generates an IndexError.

Submitted by admin on Thu, 03/11/2021 - 17:05