On this page
random.randint
Prev: random.randbytes | Up: random | Next: random.random
Rel: random.betavariate, random.binomialvariate, random.choice, random.choices
Ref: docs.python.org — random.randint
Tags: #public #python3 #stdlib #random
Import
import random
from random import randint
Signature & Overview
random.randint(a, b)
Return random integer in range [a, b], including both end points.
Usage
import random
rng = random.Random(1)
die = rng.randint(1, 6)
assert 1 <= die <= 6
Gotchas
- BOTH endpoints are inclusive (
a <= N <= b): Unlikerange()andrandrange(),randint(1, 6)can return6.
REPL Inspect
from random import randint
help(randint)
Linked from
Related notes
- tuts/python3/stdlib_module/random/randbytes Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/random Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/betavariate Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/binomialvariate Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/choice Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/choices Linked here; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/random/expovariate shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/gammavariate shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/gauss shared tags: #random, #stdlib