forked from sybrenstuvel/python-rsa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandnum.py
More file actions
33 lines (26 loc) · 868 Bytes
/
randnum.py
File metadata and controls
33 lines (26 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Functions for generating random numbers."""
import os
import struct
from rsa import common, transform
def read_random_bits(nbits: int) -> bytes:
"""Reads 'nbits' random bits.
If nbits isn't a whole number of bytes, an extra byte will be appended with
only the lower bits set.
"""
pass
def read_random_int(nbits: int) -> int:
"""Reads a random integer of approximately nbits bits."""
pass
def read_random_odd_int(nbits: int) -> int:
"""Reads a random odd integer of approximately nbits bits.
>>> read_random_odd_int(512) & 1
1
"""
pass
def randint(maxvalue: int) -> int:
"""Returns a random integer x with 1 <= x <= maxvalue
May take a very long time in specific situations. If maxvalue needs N bits
to store, the closer maxvalue is to (2 ** N) - 1, the faster this function
is.
"""
pass