Python Number uniform() Method


Contents

Description

The uniform() method in Python Number is supposed to return a random float r, where x is lesser than or equal to r and also r is less than y. The uniform() function belongs to the random library of Python 2 and Python 3. The parameters x and y specify the lower and upper limit of the random number respectively that are required to generate.

Syntax

Here is the syntax for uniform() method:

uniform(x, y)

Note − One cannot access this function directly, so it is required to import the random module in Python and then we are supposed to call this function making use of the random static object.

Parameters

  • x − It is used to set the lower limit of the random float.
  • y − This is used to set the upper limit of the random float.

Return Value

This method in random number functions of Python returns a floating point number.

Example

The example below shows the usage of uniform() method.

#!/usr/bin/python
import random

print "Random Float uniform(5, 10) : ",  random.uniform(5, 10)
print "Random Float uniform(7, 14) : ",  random.uniform(7, 14)

Let us run the above program, this will produce the following result:

Random Float uniform(5, 10) :  5.52615217015
Random Float uniform(7, 14) :  12.5326369199

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial