Random Numbers in Python
Here’s the translation of the Go code to Python, formatted in Markdown suitable for Hugo:
Python’s random
module provides pseudorandom number generation.
Some of the generated numbers may be different when you run the sample.
The random
module in Python provides various functions for generating random numbers. Here are some key points:
random.randint(a, b)
generates a random integer N such that a <= N <= b.random.random()
generates a random float between 0.0 and 1.0.random.uniform(a, b)
generates a random float N such that a <= N <= b.- You can create a separate random number generator with a fixed seed using
random.Random(seed)
.
For cryptographically secure random numbers, you should use the secrets
module instead.
See the Python random
module documentation for references on other random quantities that Python can provide.