In Hungarian, stems ending in a back vowel plus one or more neutral vowels show unusual behaviour: for such stems, the otherwise general process of vowel harmony is lexically idiosyncratic. Particular stems can take front suffixes, take back suffixes or vacillate. Yet at a statistical level, the patterning among these stems is lawful: in the aggregate, they obey principles that relate the propensity to take back or front harmony to the height of the rightmost vowel and to the number of neutral vowels. We argue that this patterned statistical variation in the Hungarian lexicon is internalised by native speakers. Our evidence is that they replicate the pattern when they are asked to apply harmony to novel stems in a ‘wug’ test (Berko 1958). Our test results match quantitative data about the Hungarian lexicon, gathered with an automated Web search. We model the speakers' knowledge and intuitions with a grammar based on the dual listing/generation model of Zuraw (2000), then show how the constraint rankings of this grammar can be learned by algorithm.