Wouldn't it be easier to use a periodic function like sin? Then clamp the values between 300 and 500?