The random.sample() is an inbuilt function in Python that returns a specific length of list chosen from the sequence. For example,  list,  tuple,  string, or set. If you want to select only a single item from the list randomly, then use  random.choice().

Python random sample()

To find a random sample pick from the sequence like list, tuple, or set in Python, use random.sample() method. The random.sample() function is used for random sampling and randomly pick more than one item from the list without repeating elements.

The random.sample() returns the list of unique items chosen randomly from the list, sequence, or set, and we call it random sampling without replacement.

If your list itself contains the repeated or duplicate items, then random.sample() can choose repeated items because each occurrence is the possible selection in the sample.

For example, the random.sample() can pick the repeated elements from the specified list if the unique members are less than the sampling size.

#python

Python random sample: How to use random.sample()
3.40 GEEK