<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def weight(weights):
 """ RETURN RANDOM INDEX INTO WEIGHT ARRAY, GIVEN WEIGHTS """

        total = sum(weights)

        p = SEED.random()
        acc = 0
        for i, w in enumerate(weights):
            acc += w / total
            if p < acc:
                return i
        return len(weights) - 1