On this page
  1. random.choices
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

random.choices

Prev: random.choice | Up: random | Next: random.expovariate
Rel: random.betavariate, random.binomialvariate, random.choice, random.expovariate
Ref: docs.python.org — random.choices
Tags: #public #python3 #stdlib #random


Import

import random
from random import choices

Signature & Overview

random.choices(population, weights=None, *, cum_weights=None, k=1)

Return a k sized list of population elements chosen with replacement.

Usage

import random

rng = random.Random(7)
draws = rng.choices(["common", "rare"], weights=[9, 1], k=5)
assert len(draws) == 5

Gotchas

REPL Inspect

from random import choices
help(choices)

Linked from

Related notes