Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben wohlben

  • Kiel
View GitHub Profile
@wohlben
wohlben / wtd_choices.py
Created Jan 10, 2018 — forked from Dowwie/wtd_choices.py
As of Python3.6, random.choices offers weighted choices
View wtd_choices.py
age_groups = [lambda: random.randint(18,25),
lambda: random.randint(25,40),
lambda: random.randint(40,90)]
age_group_probs = [.5, .3, .1]
def get_choices():
pop_choices = random.choices(age_groups, weights=age_group_probs, k=10)
population = list(map(lambda x: x(), pop_choices))
You can’t perform that action at this time.