How to generate a random float number using math module in python

Viewed 1631

Can random float numbers be generated through using math module?

1 Answers

From my experience dealing with python, I can only say that the random function can help in generating random float numbers. Take the example below;

import random

# Random float number between range 15.5 to 80.5
print(random.uniform(15.5, 80.5))

# between 10 and 100
print(random.uniform(10, 100))

The random.uniform() function returns a random floating-point number between a given range in Python

The two sets of code generates random float numbers. You can try experimenting with it to give you what you want.

Related