A stable position can obviously be found for a three-legged table on an uneven surface. It is also true that a stable position can also be found for a rectangular four-legged table on a smoothly uneven surface. Rotate the table, keeping the same three legs on the surface, and a stable position must be found before the table reaches a position similar to the starting position.
As an exercise, a Python script was written to simulate this method of stabilising a wobbly table. For the height of the surface, a 5 × 5 grid of random integers in the range 0 - 49 was resized to 1000 × 1000 by bicubic interpolation. This surface is mapped in the diagram below by colouring grid points with odd values white and grid points with even values grey.
A 200 × 200 table is placed with its centre at a given position. Placing three legs of a table on a continuous surface requires finding vertices on the surface which form a triangle with sides of the correct length. In the simulation, the vertices are constrained to fall on grid points, so the lengths of the sides are usually not exactly right. The vertices are jiggled to get the best match to the side lengths, while keeping the centre of the diagonal (and of the table) constant in the x-y plane. The fourth leg of the table is positioned to make opposite edges of the table parallel in 3D space.
To rotate the table, the vertices of the diagonal of the surface triangle are jiggled by -1, 0, +1 in the x and y directions in such a way that they rotate clockwise about the centre of the diagonal. The other vertex is jiggled by -1, 0, +1 in all directions. The position is chosen which minimises the side length errors. The table is stable when the z coordinate of the fourth leg is on the surface at its grid point:. Each rotational step must change the x - y coordinates of at least two of the vertices, so the height of the fourth leg can change by two or more units. This could result in the stable position being missed.
The distance of the fourth leg from the surface can be plotted as the table rotates through 180º.
For a rectangular table, especially a long one, where the ends can be in well-separated regions of the surface, the behaviour is more complicated (as is the proof Mathematical table turning revisited that there is a stable position, which is clearly explained by Burkard Polster):-
This diagram shows the rotation to stability of the table as it is moved around on the surface. It would of course have been less jerky without the discrete approximations of this simulation.