Beyond 50 yards I would prefer a rifle, from 5 to 50 it would be a shotgun. From 1 to 5 yards a pistol or revolver.
From zero to a yard, maybe a pistol again but I probably would be more afraid of a guy holding a short battle axe.
You don’t let them get in from 0 to 3 yards. Anything 20-25 feet or closer if you aren’t already drawn and on target they’ll probably be able to get to you. Not saying they’ll kill you but I’m saying they may be able to get a hit on you.
Inside of 3 yards I’d almost (almost) prefer a longsword, or maybe a combat tomahawk and short-sword to a gun. At that range, even the gun has to be already out and ready. It’s too late.
This begs the value of learning some basic ringen techniques (hand to hand combat) unarmed against an armed opponent. At close quarters it is essential to have some idea how to take a knife or gun from somebody. If they have the advantage first, it’s the difference between surviving and dying.