random.choices: Get Weighted Random Choices From a Python List

random.choices: Get Weighted Random Choices From a Python List

If you want to get a list of random elements from a specific list, use random.choices. This method also allows you to weigh the possibility for each value with the weights parameter.

In the code above, I use random.choices to get a list of 10 random values. 0 is two times more likely to be selected than 1 and is ten times more likely to be selected than 2.

My previous tips on Python list.

Search

Related Posts

Related Posts

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran