uniform() method in Python Random module (original) (raw)

Last Updated : 11 Jul, 2025

The uniform() method in Python generates a random floating-point number within a specified range. It belongs to the random module and is commonly used when a continuous random number is needed. **For example, suppose we need to generate a random float number between 1 to 10

Python `

import random

print(random.uniform(1,10))

`

**Explanation: random.uniform(1,10) generates a random float number between 1 to 10 (inclusive).

Syntax of uniform() method

random.uniform(l, u)

**Parameters

**Return Type: uniform(l, u) returns a float value.

Examples of uniform() method

Example 1. Generate random number

Generating random float number using **uniform() method.

Python `

import random

initializing bounds

l = 6 u = 9

print(random.uniform(l, u))

`

**Explanation:

Example 2. Generating Random Latitudes and Longitudes

.**uniform() method can be used to generate random latitude and longitude coordinates, including negative floating-point values.

Python `

import random

lat = random.uniform(-90, 90) lon = random.uniform(-180, 180)

print("Random Location: ",lat,",", lon)

`

Output

Random Location: 73.3285434510266 , -82.611145839544

**Explanation: