ExampleEdit & Run

Use the choices() function

#import the random module
import random

#The sequence to choose from
L = ['Python', 'Javascript', 'Ruby', 'Java', 'PHP', 'C++', 'C#', 'HTML', 'CSS']

#Choose random items from the list
print(random.choices(L, k = 3))
Output:
['Python', 'Python', 'C++'][Finished in 0.01253786007873714s]

The choices() function in the random module generates a list of random elements from a given sequence, with the possibility of duplicate elements.

Syntax:
choices(seq, weight = None, cum_weight = None, k = 1)
seq Required. This is the sequence from which the items will be chosen from.
weight Optional. Specifies the weight of each item in the sequence.  It can be a list of weights that correspond to the items in the sequence or a single weight for all items.
cum_weight Optional. Specifies a cumulative weight for each item in the sequence. Useful for creating a “bias” in the selection by making certain items more likely to be chosen than others.
k Optional. Specifies how many items to select from the sequence. defaults to 1.
Parameters:

The function returns a list containing k random elements chosen from the sequence with respect to the weights.Please note that sets and dictionaries are not sequences since the items are unordered, they, therefore, cannot be used as arguments to the choices() function, doing so will raise an error.

ExampleEdit & Run
#import the random module
import random

#the sequence to choose from
seq = range(50)

print(random.choices(seq))
Output:
[11][Finished in 0.011963724857196212s]

In the above example, we did not specify the number of elements to be  chosen, therefore, 1 element(the default ) is chosen.

ExampleEdit & Run
#import the random module
import random

#the sequence to choose from
seq = range(50)

#pick 10 random elements from the range
print(random.choices(seq, k = 10))
Output:
[34, 27, 2, 3, 19, 30, 12, 16, 24, 29][Finished in 0.011257854057475924s]

With duplicates

ExampleEdit & Run
import random 

seq = ["John", "Alice", "Bob", "Mary", 'Alice']
weights = [0.1, 0.3, 0.3, 0.3, 0.2] 

choices = random.choices(seq, weights, cum_weights=None, k=3)
print(choices)
Output:
['Bob', 'Alice', 'Bob'][Finished in 0.011468108044937253s]