A friend gives you a plate of somewhat-burnt cookies. You lament your friend’s inadequate baking skills, but you nonetheless appreciate the gesture. Then you catch a glimpse of the rest of the batch and note that most aren’t burnt in the least. Had your so-called friend randomly selected cookies from the batch when preparing your gift, it should have contained just one or two charred cookies. You narrow your eyes. You are not pleased.

To infer knowledge about an entire group, we often assume that each member of a sample is equally likely to be selected—what is called random sampling. The assumption offers a powerful (if, as in the scenario above, not always accurate) way of learning about the world: we don’t have to encounter all dogs, light sockets, or cookies in order to develop expectations about populations of dogs, light sockets, or cookies; we can do so based on our experiences with a few, sometimes even one.

A surprisingly sophisticated understanding of random sampling develops early in life. In a study published in 2009, Fei Xu and Stephanie Denison, both now at the University of California-Berkeley, familiarized 11-month-old infants with two different populations of Ping-Pong balls. Each of two containers was filled with both red and white balls, but one held a mixture that was mostly red (60 red and 12 white), while the other held a mixture that was mostly white (60 white and 12 red).

In another phase of the study, an experimenter reached into a covered box and, without looking, pulled out five Ping-Pong balls, all of the same color. Then the experimenter uncovered the side of the box to reveal the container from which the balls had supposedly been taken. In some trials this was the container with the “mostly red” population, and in other trials it was the container with the “mostly white” population. (The balls had actually been stored elsewhere in the box, inside a secret compartment.)

Note that it was always possible for samples to have been drawn from either population. But researchers wanted to know whether infants would be sensitive to how likely a population was to have produced a given sample: Would infants be more surprised—that is, spend more time gaping at the box—when it was revealed that five red balls had been drawn from a “mostly white” population than when they’d been drawn from a “mostly red” population? The infants did indeed stare longer at improbable populations.

But in addition to demonstrating that infants can assume random sampling, the study also suggests that infants know when not to assume random sampling. In a different condition, before selecting Ping-Pong balls from the box, the experimenter made it apparent that she preferred balls of one color over the other (by repeatedly choosing them from a line-up). In addition, instead of turning away during the selection process, the experimenter peered into the box. In this condition infants did not assume random sampling: neither container surprised them.

In yet a third condition, the experimenter again expressed a preference for balls of a particular color. But during selection, she was blindfolded, and thus could not act on her preference. Here the infants correctly ignored the preference, once again expressing surprise when shown a population that was unlikely given the sample.

By the end of their first year, infants are not only capable of making simple statistical inferences about samples and populations, but also capable of overriding these inferences when warranted by the specifics of the situation. How intriguing that humans grasp some aspects of random sampling so readily and flexibly while others—like the gambler’s insistence that a string of bad hands must end soon—beguile us far into adulthood.