Articles → Python → Random Functions In Python

Random Functions In Python






Random Functions




  1. choice
  2. shuffle
  3. randrange



Choice




import random

fruits = ["Apple", "Orange", "Banana", "Grapes", "Strawberry"]

print (random.choice(fruits))




Picture showing the output of the choice function in python
Click to Enlarge


Shuffle




import random


fruits = ["Apple", "Orange", "Banana", "Grapes", "Strawberry"]


print (fruits)

random.shuffle(fruits)

print (fruits)




Picture showing the output of the shuffle function in python
Click to Enlarge


Randrange




import random

print (random.randrange(1,10))




Picture showing the output of the randrange function in python
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, February 19, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250