A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-number-uniform-method/ below:

uniform() method in Python Random module

uniform() method in Python Random module

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))

Output
2.0014240090730393

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:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4