random.random
Pick a random float from 0 to 1.
Python 3.13
random.random()Return value
A float from 0.0 inclusive to 1.0 exclusive.
Examples
Same number on every run
Python 3.13
import random
random.seed(42)
print(random.random())0.6394267984578837
An event with a 30% chance
Python 3.13
import random
random.seed(5)
hits = sum(random.random() < 0.3 for _ in range(1000))
print(hits)312
Details
The result can be 0.0 but never 1.0. For a float in your own range, use random.uniform(a, b); for an integer, random.randint. To get a repeatable result, call random.seed(...) first.
