We’re using a Vex unit. There’s driver code available on this forum. Search for “sonar”.
What you are seeing does not seem unusual. If there is just one or two bad readings in a row, you can write code to ignore sudden changes.
Also, consider that vibrations from the motors, etc, can confuse the sensor. We were getting mysterious readings but only when the motors were running. Unbolting the sensor from the bot and holding it by hand eliminated the problem. We remounted it using foam.
Note that if you use bolts through the foam to the chassis, the bolts will conduct the vibrations past the foam to the sensor. Mount the sensor to the foam, then the foam to the chassis.