Easy Tutorial
❮ Python Selection Sort Python Os File Methods ❯

Python3 uniform() Function

Python3 Numbers


Description

The uniform() method generates the next random floating-point number within the range [x, y].


Syntax

Here is the syntax for the uniform() method:

import random

random.uniform(x, y)

Note: The uniform() method cannot be accessed directly; it requires importing the random module and then calling this method through the random static object.


Parameters


Return Value

Returns a floating-point number N, where if x < y then x <= N <= y, and if y < x then y <= N <= x.


Example

Below is an example that demonstrates the use of the uniform() method:

#!/usr/bin/python3
import random

print("Random float number between 5 and 10: ", random.uniform(5, 10))

print("Random float number between 7 and 14: ", random.uniform(7, 14))

The output of the above example is:

Random float number between 5 and 10:  7.054602800254241
Random float number between 7 and 14:  12.552229882744296

Python3 Numbers

❮ Python Selection Sort Python Os File Methods ❯