Ognen Teofilovski / Reuters

Heaps of research suggest that social relationships make people happier—but which relationships, specifically? A guilt-ridden afternoon with a mother-in-law might not have the same effect as drinks with a best friend. A “fair-weather friend” stands by your side only during good times.

Recently a group of researchers set out to determine whose company we actually seek out when we’re happy or unhappy. Their findings, published this month in the journal Psychological Science, suggest that when times are actually good, the people we turn to aren’t friends at all. They’re strangers.

The study’s authors looked at the moods and social interactions of more than 30,000 people, most of whom were French, over the course of a month. The data were collected through an app called 58 Seconds, which would text the participants at various times of the day and ask them to type in how they were feeling, what they were doing, and whom they were with, if anyone.

The researchers were then able to examine how the participants’ happiness related to the types of people they would spend time with a few hours after their responses, and how those interactions subsequently appeared to make them feel. To isolate the effects of different company—including friends, relatives, and strangers—the researchers controlled for characteristics that naturally caused fluctuations in the participants’ happiness, such as not being a morning person, as well as the types of activities the participants would engage in. (Going for a hike might make someone feel better than going to a meeting, after all, regardless of who joins you.)

The results suggested that social interactions go through a subtle cycle: Certain feelings lead you to certain types of people, but those people either lift or sour your mood, leading you to seek out different types of people. The study’s happiest participants did indeed spend more time with others overall. But when they were happy, the participants were more likely to venture out to spend time with strangers—and doing so reduced their happiness. If the participants felt sad, meanwhile, they were more likely to later interact with their friends, kids, or siblings. Then they felt happier after doing so.

The study’s authors provide this portrait of what their results mean: If someone were especially unhappy at noon on a Saturday, that person would be almost two times more likely to see a friend that afternoon than if he or she were especially happy at noon. Meanwhile, if that person were particularly happy, his or her odds of interacting with a stranger that afternoon would go up by 20 percent. Those interactions might then feed on each other, with strangers making the person uncomfortable and less happy and close friends cheering him or her up again—and make the person eager to spend time with more strangers.

These findings don’t necessarily match every person’s experience 100 percent of the time. The study shows only correlation, not causation, and the authors acknowledge that the direction might go the opposite way: When people know they have to engage with strangers soon, for instance, they might consciously or unconsciously try to pump themselves up and get in a more outgoing mood.

But if future research upholds this pattern, it could say something important about how our moods affect our relationships. In essence, both happiness and unhappiness promote socializing, but apparently with different goals in mind. When participants were feeling unhappy, they were more likely to subsequently spend time with people who tended to boost their happiness. Best friends and siblings can be a salve; being known allows you to skip explaining yourself and focus on the problem at hand. And you already know whose side your loved ones are going to take: yours.

On the other hand, when people were happy, they were more likely to enjoy some solitude or to suffer the temporary discomfort of trying to build their social network. You can better tolerate awkward small talk or a job-interview-like series of questions, it seems, if you already feel good.

Maxime Taquet, one of the study’s authors and a researcher at the University of Oxford and Harvard Medical School, says that in the future, it might be interesting to look at whether people with anxiety and depression follow a different pattern. If someone who is already depressed is doing something that, according to his study, is likely to make you even less happy—like spending time with strangers—that could cause the person’s mood to spiral down even further. “That might potentially explain why they’re depressed,” Taquet told me.

There are several scientific theories for how our moods affect what we do. One is the “hedonic opportunism hypothesis,” which suggests that we are always trying to feel better, regardless of what mood we are in. Another, the “hedonic salience hypothesis,” suggests we try to feel better when we feel especially happy or sad, but when we feel kind of neutral, we undertake less pleasant, yet necessary, activities, such as chores.

This new study’s findings, meanwhile, are an example of the hedonic flexibility principle, which suggests that people prioritize different goals based on their emotional state. When we feel bad, the goal is just to feel good again. But when we feel happy, we’re more likely to sacrifice some of the comfort of old, worn-in relationships in order to achieve longer-term goals, like networking or making new friends. We can use our happiness to give us the energy to reach out to new people. Those strangers, in turn, may become the very friends we rely on once we feel bad again.

“This suggests that happiness is a resource,” Taquet says, “rather than the ultimate goal you have in your life.”

We want to hear what you think about this article. Submit a letter to the editor or write to letters@theatlantic.com.