Latest web development tutorials

Python uniform () function

Python figures Python figures


description

uniform () method to generate the next random real number in [x, y] range.


grammar

The following is the syntax uniform () method:

import random

random.uniform(x, y)

NOTE: uniform () is not directly accessible, we need to import the random module, and then call the method by random static objects.


parameter

  • x - the minimum value of random numbers.
  • y - the maximum value of the random number.

return value

Returns a floating-point number.


Examples

The following illustrates the use of uniform () method Example:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import random

print "uniform(5, 10) 的随机数为 : ",  random.uniform(5, 10)

print "uniform(7, 14) 的随机数为 : ",  random.uniform(7, 14)

After running the above example output is:

uniform(5, 10) 的随机数为 :  6.98774810047
uniform(7, 14) 的随机数为 :  12.2243345905

Python figures Python figures