From: Colin Patrick McCabe Date: Mon, 14 Feb 2011 06:37:04 +0000 (-0800) Subject: Add pickrand.py X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17f7ddbe7d6b37982cf03c10330f66cff9b355cc;p=cmccabe-bin Add pickrand.py Signed-off-by: Colin McCabe --- diff --git a/pickrand.py b/pickrand.py new file mode 100755 index 0000000..8253e74 --- /dev/null +++ b/pickrand.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import os +import random +import sys + +allfiles = [] + +for root, dirs, files in os.walk(".", followlinks=True): + for f in files: + allfiles.append(os.path.join(root, f)) +if (len(allfiles) == 0): + sys.exit(1) +random.seed(None) +r = random.randint(0,len(allfiles)) +print(allfiles[r]) +sys.exit(0)