def generate(g, n):
    """Generate a (sub-)group using g as generator in modulus n"""
    result = []
    for i in range(1,n):
        val = g ** i % n
        if val != None and val > 0:
            result.append(val)
        if val < 2:
            return result