On this page
random.uniform
Prev: random.triangular | Up: random | Next: random.vonmisesvariate
Rel: random.betavariate, random.binomialvariate, random.choice, random.choices
Ref: docs.python.org — random.uniform
Tags: #public #python3 #stdlib #random
Import
import random
from random import uniform
Signature & Overview
random.uniform(a, b)
Get a random number in the range [a, b) or [a, b] depending on rounding.
Usage
import random
rng = random.Random(1)
x = rng.uniform(2.5, 5.5)
assert 2.5 <= x <= 5.5
Gotchas
- Endpoint
bmay or may not be included depending on float rounding ina + (b - a) * random().
REPL Inspect
from random import uniform
help(uniform)
Linked from
Related notes
- tuts/python3/stdlib_module/random/triangular Linked here; links to this page; shared tags: #random, #stdlib
- tuts/python3/stdlib_module/random/vonmisesvariate 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/random 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