Add pickrand.py
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 14 Feb 2011 06:37:04 +0000 (22:37 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 14 Feb 2011 06:37:04 +0000 (22:37 -0800)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

pickrand.py [new file with mode: 0755]

diff --git a/pickrand.py b/pickrand.py
new file mode 100755 (executable)
index 0000000..8253e74
--- /dev/null
@@ -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)