A few wild outliers can drag a best-fit line completely off the truth — least-squares trusts every point equally, even the liars. RANSAC does the opposite: guess a line from two random points, count how many agree, and keep the guess with the most friends. It sees the real line THROUGH the noise. Slide the outliers up and watch the two fits part ways.
RANSAC: sample two points, form the line through them, count INLIERS (points within a tolerance), and after many tries keep the model with the most inliers. Because it scores by agreement it is immune to a minority of arbitrary outliers, where least-squares — minimising squared error over ALL points — is dragged toward them. A fail-loud self-check builds 40 points on y=3x+2 plus 25 wild outliers and throws unless RANSAC recovers slope ≈ 3 while least-squares is pulled more than 0.5 away — robustness demonstrated, not asserted.
RANSAC is randomised (seeded here for reproducibility) and needs a sensible inlier tolerance and enough iterations; with more outliers than inliers it fails. The inlier-count scoring and its advantage over least-squares under outliers are exact.