You may think you've picked your friends from shared jokes and chance encounters, but science suggests that genetics may have a big role to play.
According to a new study, you and your friends may share a high number of similar genes.
Researchers made the discovery after analysing almost 1.5 million markers of gene variation from around 2,000 people.
Pairs of unrelated friends were compared with pairs of unrelated strangers. The study found that, on average, about 1% of the genes of friends matched each other.
Friends with no biological connection had as much genetic similarity as fourth cousins or people who share great, great, great grandparents.
US lead scientist Professor James Fowler, from the University of California at San Diego, said: "Looking across the whole genome, we find that, on average, we are genetically similar to our friends. We have more DNA in common with the people we pick as friends than we do with strangers in the same population."
Focusing on different sets of genes revealed that those affecting sense of smell were among the most similar in friends.
A possible reason is that our sense of smell draws us to similar environments, say the scientists.
People who enjoy the aroma of coffee, for instance, may be more likely to frequent cafes, providing an opportunity to make friends with others of a similar disposition.
The opposite was true for genes controlling immunity. Friends were more likely than strangers to have different genetic defences against various diseases.
A dissimilarity between immune system genes is also seen in spouses. The scientists believe it may reflect the evolutionary advantage of connected people withstanding a wide range of infections, thereby reducing the likelihood of epidemics.
How we select friends with complementary immunity remains a mystery, but smell sense might provide a clue.
Pheromone scent signals are thought to play a role in sexual attraction between men and women with different immune systems.
Generally, shared traits may contribute to advantageous "functional kinship" - getting together for practical reasons, the researchers point out.
For example, a friend who feels the cold as much as you do is likely to build a fire that benefits you both.
In addition, some attributes, such as speech, will only work if others have them too.
"The first mutant to speak needed someone else to speak to," said Prof Fowler. "The ability is useless if there's no-one who shares it. These types of traits in people are a kind of social network effect."
The findings, published in the journal Proceedings of the National Academy of Sciences, enabled the team to make calculated guesses about which individuals were likely to be friends.
Using a "friendship score" based on gene variants they predicted friendships with about the same level of confidence that the genetic risk of obesity or schizophrenia can be estimated.
Co-author Professor Nicholas Christakis, from Yale University in New Haven, US, said: "One per cent may not sound like much to the layperson, but to geneticists it is a significant number. And how remarkable: most people don't even know who their fourth cousins are. Yet we are somehow, among a myriad of possibilities, managing to select as friends the people who resemble our kin."
Another surprising discovery was that those genes most resembling each other in friends also seemed to be evolving faster.
This may help to explain why human evolution has speeded up over the last 30,000 years, and suggests that social environment is an evolutionary force, say the scientists.