Neural responses in the visual cortex of awake animals are highly variable, display substantial spontaneous activity even when no visual stimuli are being processed, and the variability in both evoked activity (EA) and spontaneous activity (SA) is strongly structured. However, most theories of visual cortical function remain mute about the possible computational roles and consequences of such variability and treat it as mere nuisance or, at best, as an epiphenomenon. Here, we propose that neural response variability in EA and SA may be a hallmark of statistical inference carried out by the visual cortex and test a key prediction of this normative theory in multiunit recordings from awake ferrets. Under our working hypothesis, neural response variability represents uncertainty about stimuli: we treat cortical activity patterns as samples from an internal, probabilistic model of the environment. Thus, given a stimulus, EA can be interpreted as representing samples from the posterior probability distribution of possible causes underlying visual input. In the absence of a stimulus, this probability distribution reduces to the prior expectations assumed by the internal model as reflected by SA. This interpretation of EA and SA directly leads to a critical prediction about their relation: if they represent samples from the same, statistically optimal model of the environment, then the distribution of spontaneous activity must be identical to that of evoked activity averaged over natural stimuli. In practice, a perfect identity may not be achieved, but crucially, the two sides of this equation should become closer as the internal model of the environment implemented by the cortex is being matched to the statistics of natural scenes. We analyzed multiunit data from 14 awake P29-151 ferrets recorded with a linear array of 16 electrodes. Neural activity was recorded in two conditions: while the animal was watching a movie (EA), and while the animal was in complete darkness (SA). Neural data was discretized in 2ms bins and binarized. We constructed the joint distribution over possible states of the 16 channels in the two conditions, PEA and PSA, and computed the Kullback-Leibler (KL) divergence, a standard measure of statistical dissimilarity between these two distributions. We found that after visual development the distribution of EA was very close to that of SA (less than 1.5% of the minimum coding cost), that this similarity significantly increased with visual experience, and that it was brought about by a match between the spatial correlational structure of the activity patterns, rather than merely by preserved firing rates across conditions. A similarly significant increase in the match between the temporal correlational structure of EA and SA was also found. In addition, we found that classical theories of visual cortical function based on independence and sparseness were not supported by our data. These results suggest that neural variability samples from a probabilistic model of the environment that is gradually being tuned to natural scene statistics by sensory experience as the visual system develops.