Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Weighted Random Values In Python

This is how to weight the return value of a seleciton

python
import random

items = ['alfa', 'bravo', 'charlie', 'delta']
weights = [10, 20, 60, 10]

single_item = random.choices(items, weights, k=1)[0]
print(single_item)

weighted_list = random.choices(items, weights, k=5)
print(weighted_list)
results start