Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

How to use the random uniform() method in Python

Onyejiaku Theophilus Chidalu

Overview

The random.uniform() method in Python is used to return a random floating-point number that is greater than or equal to the specified low boundary, and less than or equal to the specified high boundary.

Syntax

random.uniform(a, b)

Parameters

Parameter Description
a a is the number that specifies the lowest boundary the return value should have; this parameter is required.
b b is the number that specifies the highest boundary the return value should have; this parameter is required.

Example

Let’s look at a very simple way to use the random.uniform() method. Let us write a code to generate a random float number starting from 5 and ending at 10.

import random

print(random.uniform(5,10))

Explanation

  • Line 1: We import the random module.
  • Line 3: We use the random.uniform() method to return a random float number starting from 5 and ending at 10.

RELATED TAGS

python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring