import secrets
import random


def get_challenge(len):
    """
    Return a random challenge, of a given number of bytes.
    """
    if secrets:
        return secrets.token_bytes(len)
    # random.randbytes only exists from 3.9 onward, by which point we should
    # use secrets, which is already handled.

    return bytes(bytearray([random.randrange(256) for _ in range(len)]))