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

secrets.choice

Up: secrets | Next: secrets.compare_digest
Rel: secrets.compare_digest, secrets.randbelow, secrets.randbits, secrets.SystemRandom
Ref: docs.python.org — secrets.choice
Tags: #public #python3 #stdlib #secrets


Import

import secrets
from secrets import choice

Signature & Overview

secrets.choice(seq)

Choose a random element from a non-empty sequence.

Usage

import secrets
import string

alphabet = string.ascii_letters + string.digits
code = "".join(secrets.choice(alphabet) for _ in range(12))
assert len(code) == 12

Gotchas

REPL Inspect

from secrets import choice
help(choice)

Linked from

Related notes