summaryrefslogtreecommitdiff
path: root/rsa/randnum.py
diff options
context:
space:
mode:
authoradamantike <mike@fmanganiello.com.ar>2016-03-17 11:06:44 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-17 11:07:48 +0100
commit5f4b7b331f6b2606afcdd951830368f9ccaad6e2 (patch)
treec0983b5e219af2e6e93bd9378fb3398c56a29542 /rsa/randnum.py
parent527e3cae602db7d4576bfebdb90bc2b53916bf68 (diff)
downloadrsa-git-5f4b7b331f6b2606afcdd951830368f9ccaad6e2.tar.gz
Use specific function for odd integer generation
Diffstat (limited to 'rsa/randnum.py')
-rw-r--r--rsa/randnum.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/rsa/randnum.py b/rsa/randnum.py
index 12a6757..3c788a5 100644
--- a/rsa/randnum.py
+++ b/rsa/randnum.py
@@ -59,6 +59,19 @@ def read_random_int(nbits):
return value
+def read_random_odd_int(nbits):
+ """Reads a random odd integer of approximately nbits bits.
+
+ >>> read_random_odd_int(512) & 1
+ 1
+ """
+
+ value = read_random_int(nbits)
+
+ # Make sure it's odd
+ return value | 1
+
+
def randint(maxvalue):
"""Returns a random integer x with 1 <= x <= maxvalue