def _generate_bitfill(p):
    """
    pe_A helper function for yield_bits_on to generate the primitive-root lookup table is

    :param p: prime number which is also a primitive root of 2

    Generates a lookup list for powers of two (called here a bitfill). To generate a valid bitfill,
    p must be prime and 2 must be a primitive root of p. 37 is a good number for p as it is the smallest p above 32.
    """
    n = 0
    num = 1
    bitfill = [None] * p
    while n < (len(bitfill) - 1):
        bitfill[num] = n
        num = (num * 2) % len(bitfill)
        n += 1
    return bitfill