Is the tilemap a side-scrolling map or a top-down one? I assume the former from your image. (edit: I saw your second post after posting this one, obviously sidescrolling)
Here's a capx example:
https://www.dropbox.com/s/nhwqq14d716xy ... .capx?dl=1
Basically for bridges or straight slopes you only need to use the a or m (slope) parameter of a linear function. You go from the lower x to the upper x and add a to Y with every loop iteration.
For filling terrain of a random height you need to nest a loop that will fill terrain from the bottom to it top (or vice versa) within the loop going from the lower x to the upper x. Every time you go to the new x you pick a random Y that will be your top.
With some tinkering you can also clamp the random Y's so that the height difference between x and x+1 is of a given maximum. Basically something like Y=Y+floor(random(0,3)*choose(-1,1). That will generate the height at the next X position at most 2 tiles lower or higher than the previous x position. The terrain would be more even yet still jagged at places.