summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--util.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/util.py b/util.py
new file mode 100644
index 0000000..7051134
--- /dev/null
+++ b/util.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+
+from random import Random
+
+rng = Random()
+
+righthand = '23456qwertasdfgzxcvbQWERTASDFGZXCVB'
+lefthand = '789yuiophjknmYUIPHJKLNM'
+allchars = righthand + lefthand
+
+def generate_char(i, alternate_hands):
+ if not alternate_hands:
+ return rng.choice(allchars)
+ else:
+ if i%2:
+ return rng.choice(lefthand)
+ else:
+ return rng.choice(righthand)
+
+def generate_password(length = 8, alternate_hands = True):
+ return ''.join([generate_char(i, alternate_hands) for i in xrange(length)])
+