Referencing previous integer in a list of numbers

Hi all, running into an issue I suspect someone can solve by pointing me to a specific function:

Background: Im designing a screen that undulates up and down semi-randomly. I have a base surface wall which I’ve modelled in rhino and using grasshopper it’s been divided into 3M lengths and a curve is placed at these 3M intervals. These curves (consider them posts on the screen) are divided into 6 points and currently I’ve managed to get grasshopper to pick a random point between numbers 3 to 6 (top half of the wall basically) and join them to create a truly random polyline to define the top of this screen (image attached and working as intended). I actually now want to ensure that this line only moves randomly either one point up, one point down or stay at the same level when moving along the polyline (eg. pt6 > pt5 > pt5> pt>4 >pt5) still between points 3 and 6.

Predicament: So I think the best way to do this is to nail down a working list of numbers which follow the rule I set out above ( +1, 0, -1) and use the list item function as before to connect each of these points to create a polyline. I’ve managed to create a list which randomly generates +1, 0, -1. However now I need to create a set of numbers to add these to and these figures need to be able to self-reference - For example we start with a 5, the other list I’ve already generates +1, giving 6. Then the next down the list takes this 6, and adds 0, giving 6 again. Next is 6, adds -1, giving 5. Next is 5 adds -1, giving 4. You get the idea. Repeat around 200 times.

It’s the part where I make it reference the figure from the figure above it in the list which i can’t work out. Impossible? Bonus points for anyone who can help me keep the figures between 3 and 6.

Thanks all

Grasshopper (7.7 KB)