Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to use the "import random" in-built model in python

import random

movies_list = ['The Godfather', 'The Wizard of Oz', 'Citizen Kane', 'The Shawshank Redemption', 'Pulp Fiction']

# pick a random choice from a list of strings.
movie = random.choice(movies_list)
print(movie)
# Output 'The Shawshank Redemption'


#To make two random selection from the list use the below code
for i in range(2):
    movie = random.choice(movies_list)
    print(movie)
# Output 
# 'Citizen Kane'
# 'The Shawshank Redemption'
Source by pynative.com #
 
PREVIOUS NEXT
Tagged: #model #python
ADD COMMENT
Topic
Name
4+9 =