Answer by Joshua Engel,
Gandalf was an Istari, one of the Maiar, of the same order as Sauron.
It's never entirely clear how much he could predict of the future. He often seemed quite prescient, but not from special knowledge of the Music of Illuvatar. Rather, he's just the wisest of the Wise, and he seems to have developed a very strong intuition about the flow of history.
Especially in the light of LotR, it's hard not to see it as connected to The Ring. He couldn't possibly have foreseen it as it occurred, but he has always had a special connection to the Hobbits, and I can't help but think he wanted to put a Hobbit in the way of these great events. (One wonders if other Hobbits of the Took family have disappeared without a trace while Gandalf took a few practice swings...)
The Hobbits play a strange place in the story of the Ring. They go almost unmentioned in The Silmarillion. In the story of the Third Age and the Rings of Power, hobbits get only a passing mention. Yet they are fundamental to the story, not just by coincidence. They are specifically chosen for being underestimated, strong of heart rather than of stature.
For The Hobbit, I suspect that Gandalf knew that the Hobbits would play this role. He wanted to train up a Hobbit to fulfill that destiny, and he selected one from the adventurous Took family. I don't believe it's a supernatural event, merely a wise man who could see that Bilbo had what it took to introduce the notion of adventuring to the Hobbit race.
Coming upon the Ring wouldn't have figured into it, though I suspect that Gandalf wouldn't have been too surprised by it. The Ring itself seems to have a fondness for Hobbits, perhaps out of a feeling that their small stature would make them weak of heart. In fact, it has imbued in them low demands for their life, as opposed to Men, who have literally striven with the Valar for greatness.
In Bilbo, Gandalf found the perfect compromise: adventurous enough to play a role in big stories, and small enough to not demand it all for himself. Bilbo even gives up the Arkenstone to make peace, just in time for the Battle of the Five Armies.More questions on The Hobbit (book, movies and creative franchise):