Python Float – Generate a random float between a range

In this post we will be creating a Python script that will generate a random float between a given range. To do this we will be using the the random module which implements pseudo-random number generators.

In particular we will be using the ‘uniform()’ function which will return a random floating point number in between a given range. See the example below where we use the ‘uniform()’ function to generate a float in between ‘2.4’ and ‘2.8’.

import random

Random_float = random.uniform(2.4, 2.8)
print(Random_float)

An example of what the above would output can be seen below.

1.887089482805229
>>> 

Leave a Reply