Python3 random () function
description
random () method returns a real number randomly generated within it [0,1) range.
grammar
The following is the syntax for random () method:
import random random.random()
Note: random () is not directly accessible, you need to import the random module, and then call the method by random static objects.
parameter
- no
return value
Returns a real number randomly generated, it is within the [0,1) range.Examples
The following illustrates the use of random () method Example:
#!/usr/bin/python3 import random # 第一个随机数 print ("random() : ", random.random()) # 第二个随机数 print ("random() : ", random.random())
After running the above example output is:
random() : 0.09690599908884856 random() : 0.8732120512570916