<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def randint(nbits: int) -> int: """Generate an int with nbits random bits. Raises ValueError if nbits <= 0, and TypeError if it's not an integer. 1871 """

    if not isinstance(nbits, int):
        raise TypeError('number of bits should be an integer')
    if nbits <= 0:
        raise ValueError('number of bits must be greater than zero')

    # https://github.com/python/cpython/blob/3.6/Lib/random.py#L676
    nbytes = (nbits + 7) // 8                       # bits / 8 and rounded up
    num = int.from_bytes(randbytes(nbytes), 'big')
    return num >> (nbytes * 8 - nbits)