How to randomly select files from folder using Python

While doing image processing using python, I wanted to select image file randomly from images folder. I found couple of ways of doing this but following is the simplest way to get random file name

 

 
import os
import random

path ='/code/github/python'
files = os.listdir(path)
index = random.randrange(0, len(files))
print(files[index])