random.random() function in Python

random() is an inbuilt function of the random module in Python3. The random module gives access to various useful functions and one of them being able to generate random floating numbers, which is random().

Syntax : random.random()

Parameters : This method does not accept any parameter.

Returns : This method returns a random floating number between 0 and 1.

Example #1: Simple implementation of sample() function.



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to demonstrate 
# the use of random() function . 
    
# import random  
from random import random 
    
# Prints random item 
print(random())

chevron_right


Output:

0.41941790721207284

Example #2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to demonstrate
# the use of random() function . 
  
# import random  
from random import random
   
lst = []
  
for i in range(10):
  lst.append(random())
    
# Prints random items
print(lst)

chevron_right


Output:

[0.12144204979175777, 0.27614050014306335, 0.8217122381411321, 0.34259785168486445, 0.6119383347065234, 0.8527573184278889, 0.9741465121560601, 0.21663626227016142, 0.9381166706029976, 0.2785298315133211]

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.