Only a micro black hole likely in near future. But the sun is a far bigger target for those than the Earth - and is also going to be easier for it to stop the black holes if going at speed.
So it's the sun you need to be concerned about if anything. We don't see stars blinking out in the sky - so micro black holes must be rare.
Summary for normal stellar mass black holes - This is just exceptionally unlikely. Theoretically it is possible but as far as worrying about it, forget about it.
The chances of getting closer than Neptune in any one million year period are
The chances of getting as close as Earth, hitting Earth or hitting the Sun are vanishingly small.
HOW MANY OF THEM ARE THERE WITHIN TWELVE LIGHT YEARS?
With The volume of the Milky Way, our galaxy, is roughly 8 trillion cubic light years, the calculations are simplified if we look at a volume of 8 thousand cubic light years, i.e. in a sphere of radius twelve light years.
Our galaxy has 400 billion stars (you get various estimates here, some say 100 billion, I’m going by the higher estimate) which makes it around 200 normal stars in that same 8,000 cubic light years. About one star in a thousand is a black hole. See Black Holes. So that same 8,000 cubic light years would have 0.2 black holes on average.
SO HOW LIKELY IS IT THAT A STAR DOES A FLYBY?
Stars, even though they are much more common, are also very unlikely to do close passes of the solar system. Never mind hitting the Earth, or the sun, they are extremely unlikely to get as close as Pluto. The closest flyby of a star in recent past is Scholtz's star, which passed 0.8 light years (around 9.6 light months) away 70,000 years ago. https://www.sciencedaily.com/rel...
By comparison Pluto is 5.5 light hours away. So - when a very rare close encounter may take a star 9-10 light months away - how likely is it that a star would pass as close as 5.5. light hours away? With neutron stars a thousand times less common than stars, how likely that a neutron star would come anywhere near our solar system?
To get close enough to pass between Earth and the Moon it would need to pass just one light second away. To hit Earth it would need to hit us accurately to the nearest 0.02 light seconds - within two hundredths of a light second. The sun’s diameter is 4.64 light seconds, so to hit the Sun it would need to get within a few light seconds of it.
I think you can see that all these things are so unlikely it will surely never happen.
IMPOSSIBILITY OF CAPTURE
It is just a single pass, because if any rogue planet, or neutron star, or black hole or anything were to pass through our solar system - it would be going too fast to do anything except just fly out again.
Capture into solar system orbit by Jupiter - tracing the path of Voyager 2 or Voyager 1 backwards - is so very improbable you can forget about it. It is easy for a solar system to eject a planet, and very hard for it to capture one. That’s a bit like the way it is easy for a cup to break but very hard for a cup to spontaneously assemble from the broken pieces on the floor.
Another analogy - it would be theoretically possible to drop a pin on a hard polished floor and for it to land point down balanced exactly. And if all the tiny drafts of air pushed in the right way to keep it balanced, it could stay balanced like that for an hour or more. It's possible but surely even with the thousands of pins dropped on polished floors, it's surely never happened in the history of humanity!
EXACT CALCULATION OF THE CHANCES
So now, what is the chance that Earth or the Sun is hit by a black hole, or that it comes into our solar system?
I’ve found a way to do an exact calculation
There's a formula, we can use here, from Perturbation of the Oort Cloud by Close Stellar Approaches. Our sun has approximately 4.2*D^2 encounters with other stars every million years.
There D is the diameter in parsecs of the spherical region around the star.
Neptune's semi major axis is 4.49506 billion kilometers so it's diameter is around 0.00029135 parsecs. So substituting that for D, every million years there is 1 chance in 2.8 million (calculated as 1/(4.2*0.0002913^2)) of a star passing closer to the sun than Neptune.
For black holes, then as only one star in a thousand forms a black hole, then that makes it once chance in 2.8 billion of a black hole coming closer than Neptune.
Now for the chance of a star hitting the Earth. Now D is 12,742 km, which is 4.129401e-10 parsecs. So now the calculation is one in 1/(4.2*(4.129401e-10)^2).
So the chance of a star hitting Earth in the next million years is about 1 in 1.3962931 * 10^18. Or about 1 in 1,400,000,000,000,000,000
We can also look at the chance of a star hitting the Sun. Now D is 1.3914 million km, or 4.5092203 × 10^-8 Parsecs 1/(4.2*(4.5092203e-8)^2) makes it 1 chance in 117,000,000,000,000.
Multiply those numbers by a thousand and to summarize, every million years there is a
So about one chance in 117,000,000 billion of it happening every million years. With 400 billion stars in the galaxy, we get one chance in 117,000,000/400 or about one chance in 300,000 that we get a collision between two stars somewhere in the galaxy every million years. With the galaxy 13.21 billion years old, then it may have happened 13,210/300,000 times or about 0.044 times since the galaxy formed, that a black hole has hit another star.
Those are averages though. The stars are much more densely packed in the center of the galaxy, so stellar collisions there should be more common. The galaxy also has a giant black hole in its core, and stars must collide with it quite often. I’ve also assumed that there is not enough gas or dust to cause significant drag on the approaching object. That’s true for our sun but not true for newly born stars or stars that hit the accretion disk of a black hole.
However, we orbit far from the galactic center, and are at no risk of collision, no more risk than Earth is at risk hitting the sun, because we orbit the galactic center in a long term stable orbit.
In the universe as a whole, there are so many stars that such collisions are common. Collisions of a neutron star with a black hole cause some of the enigmatic gamma ray bursts - the shorter ones.
Artist’s impression of a neutron star captured by a black hole. In a Flash NASA Helps Solve 35-year-old Cosmic Mystery
This is of no danger to Earth whatsoever
So not a big issue. As for the collision with the Andromeda galaxy, in collisions of two galaxies, stars are so far apart that the chance of the sun colliding with anything at all is minute, it’s similar to the chance of two stars hitting each other in our own galaxy.