Keep the text the rain in spain stays mainly in the plain, the pattern ain and the base 256, and set the modulus to 1000003. The pattern now hashes to 383964, four windows hash to that value, all four are occurrences, and the panel's collision counter reads 0. The verification bill is 12 characters, which is 4 × 3 and cannot be lower.
That is the good case, and the page does not stop there. The lower table keeps this text and this base and replaces the modulus by every prime below 200 in turn.
the 46 primes under 200, on this text at base 256
collide (18) 2 3 5 7 13 17 23 29 37 41 47 53 67
103 109 113 131 137
clean (28) 11 19 31 43 59 61 71 73 79 83 89 97 101
107 127 139 149 151 157 163 167 173 179 181 191 193
197 199
worst modulus 2 with 18 collisions on 41 windows
largest that collides 137
smallest that is clean 11
Theorem · The collision set is not an intervalThere exist a text, a pattern and a base together with two primes q1 < q2 such that the hash collides at q2 and not at q1. So no threshold Q exists with the property that every modulus above Q is collision-free for a given input.
The table above exhibits one: with the text the rain in spain stays mainly in the plain, the pattern ain and base 256, the modulus 11 produces no spurious hit and the modulus 137 produces three.
A single instance settles the statement because the claim is existential. The reason is that a collision at modulus q means q divides the difference between two particular integers, and divisibility of a fixed number is not a monotone property of the divisor: 137 divides one of these differences and 11 divides none of them.
□
That proof shape is worth noticing because it is the opposite of the one this course usually needs. Here the measurement is the proof: the claim is that something exists, and a single exhibited pair establishes it. The claims that measurement cannot establish are the universal ones, and the next paragraph is about one of those.
What is actually proved about Rabin–Karp
Fix the text, the pattern and the base. A window collides at modulus q exactly when q divides the difference between that window's value and the pattern's. Each of those differences is a fixed integer below b^m, so it has at most m log b / log q prime divisors above q, and choosing q at random from a range of size R makes the chance that it divides any of the n differences at most a bound of the form n m log b / (R log R). That is the theorem, and its subject is the random choice.
Read what it does not say. It does not say that a particular large prime is safe on a particular text — 137 is not, here. It does not say the collision count falls as the modulus rises — the table shows 41 and 47 colliding while 43 does not. And it says nothing at all if the modulus is a constant in the source, because then there is no random choice to average over and an adversary can construct a text against it.
The cost of a collision, and why a small modulus is not merely inelegant
Each candidate costs m character comparisons to settle. At modulus 41 this text produces 7 candidates and a bill of 21 characters, of which 9 are wasted; at 1000003 it produces 4 and a bill of 12, with nothing wasted; at modulus 2 it produces 22 candidates, of which 18 are collisions. In the worst direction the verification dominates and the algorithm degenerates towards comparing every window in full, which is the naive matcher with extra arithmetic.
So the modulus is not a tuning detail. It decides how much of the algorithm's advertised advantage — constant work per window — survives contact with the input, and the only defensible way to choose it is at random from a large range, because that is the one choice the theorem covers.
The same sweep on a different text
Switch the preset to the binary one, where the alphabet is two characters and the base is 2, and the sweep reports 6 of the 46 primes colliding rather than 18. Switch to the repetitive abracadabra text at base 256 and it reports 15. The number is a property of the input triple and moves by a factor of three between presets, which is a third way of making the same point: it is not a constant of the method.