MENU
Question -

Describe Random numbers function in Python with example.



Answer -

Description : The method random( ) returns a random float r, such that 0 is less than or equal to r and r is less than 1.
Syntax: Following is the syntax for
random() method
random()
Note : This function is not accessible directly so we need to import random module and then we need to call this function using random static object.
Parameters: NA
Return Value : This method returns a random float r, such that 0 is less than or equal to r and r is less than 1.
Example: The following example 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()

This will produce the following result:

random(): 0.281954791393
random(): 0.309090465205

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×