Python random() Function
Description
random()The method returns a randomly generated real number in the range [0,1).
Syntax
The following is the syntax of the random() method:
import random random.random()
Note:random() cannot be accessed directly; you need to import the random module, and then call the method through the random static object.
Parameters
- None
Return Value
Returns a randomly generated real number in the range [0,1).Example
The following shows an example of using the random() method:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import random
# Generate the first random number
print "random() : ", random.random()
# Generate the second random number
print "random() : ", random.random()
The output of the above example after running is:
random() : 0.281954791393 random() : 0.309090465205Other Extensions
Python Numbers