Latest web development tutorials

Python3 uniform () function

Python3 digital Python3 digital


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/python3
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) 的随机浮点数 :  7.054602800254241
uniform(7, 14) 的随机浮点数 :  12.552229882744296

Python3 digital Python3 digital