x = 0       # current value of sequence

def rand(a, c, m):
    "Generate a value between 0 and m-1"
    global x
    x = (a * x + c) % m
    return x
