The random() method in Python number is supposed to return a random float r so that 0 is less than or equal to r where r is less than 1. The random() function in the random module of python programming is a pseudo-random number generator and the function doesn’t require any arguments.
Here is the syntax for random() method:
random ( )
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.
This method of random number functions in Python Language returns a random float r, in a way that 0 is less than or equal to r and also r is less than 1.
The example below shows the usage of random() method.
#!/usr/bin/python import random # First random number print "random() : ", random.random() # Second random number print "random() : ", random.random()
When we run the above program, it produces the following result:
random() : 0.281954791393 random() : 0.309090465205
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.