Ultimately, the only way to know how you will react in a situation like that is to have been through one. That's not a good answer. I've always hated the "You have to have experience before you can do this. You can't get experience except by doing this." kind of answer.
The next best way to know is to purposely train as close as possible to realism. I currently am training in a more modern martial art that is characterized at higher levels by including and welcoming cross training with guns and other weapons. This isn't an advertisement or a martial arts forum so PM me if you want info. The training that we're undergoing focuses on preparing you for rough, out of control, unpredictable situations. We often have to "acheive the objective" (ie keep on hitting someone, find the person in a crowded room and take them down, switch between multiple attackers) while being beaten on by someone else from behind, loud random music, strobe lights, fog machine, multiple innocent people standing around, and random switches in goals right during the middle of a drill. Some schools have even used some of the "drunk-buster" goggles that simulate drunken vision.
The goal is to get you used to being presented with hundreds of pieces of information about the situation all at the same time. You have to immediately filter out everything but what is neccessary and then take exactly the steps required to deal with the situation. Being tired, overwhelmed, angry, or scared cannot be allowed to stop you from doing what you have to do.
The problem with training in this fashion using a gun is obviously that of safety. My advice would simply be to break it down into two areas of training. One of them understandably is going to have to be on the range. Ideally, you're going to need a range that will allow you to: move around through the range and work on random targets, work on things without having other shooters around, and have a spotter right there with you (ideally directly behind you at all times). Your spotter must be someone with: a good background in gun safety and at least an understanding of what you're trying to acheive. Your spotter will need to be the one to decide: what targets you will be facing and when, what disruptions/distractions/problems you will be facing, and especially if you have to stop the drill quickly due to a gun safety issue. Ideally, the sessions will focus not only on accuracy and speed, but on decision making and realism.
The second area that I would train in will require you to get a hard plastic practice gun. These are available today in brightly colored exact copies of almost every single handgun that exists. You will almost certainly be able to find a copy of your preferred carry. Or, sheesh, just cut one out of wood with a skill saw. It's best to use these during the next part so that you do not have to worry about gun safety at all and are free to focus on other areas. What you want to work on at this point is getting your weapon out and into play. I have often heard statements and VERY often made statements like, "Don't even think about it, man. I'd have a gun out and shoot you before you could do XXXX. I could be doing anything and still have a gun out before you could blink." Please leave your ego at the door. I've often said that I could do something and then ended up embarrassing myself when I actually tried to do it.
Once again, you're going to need a partner or two. Ideally, you would be able to find a skilled realistic martial artist to work with you. Wear normal clothing and carry the plastic gun holstered the exact same way you normally would. A bit of padding or foam protection can help save some bruises too. Then start working on scenarios. Here's a few that you might like to try:
Man with a knife/stick/gun/fists:
15 feet away
10 feet away
10 feet behind you, shouts your name and then attacks
10 feet away, throws a couch pillow and then attacks
Two men behind you, one screams and pulls a weapon...the other just screams
Man with a weapon attacking someone next to you.
You seated in a chair.
You seated in a booth (chair and table can't move).
You seated in a car, front seat, driver's seat, back seat.
One attacker in front of you at ten feet while someone else beats on you with a pillow, cushion, grabs your shoulders and tries to move you, grabs your arm, bumps into you from the side, starts screaming.
Starting with your eyes closed and the attacker in random locations
Someone turns out the lights two seconds into the drill
Etc...
In addition, the attacker should not stop simply because you get the gun out. Someone with a knife attacking you (training knife I hope) shouldn't just try to stab you once...it should be repeatedly. Someone trying to tackle you should nail you if you don't move. You're going to have to make your own choices between yourselves about when your attacker is going to stop, but a gun isn't some kind of magic wand. In our day of doped up idiots, it often takes a bit to stop someone. The goal in all of these drills is to force you into a confusing situation and force you to make a decision, take an action, and follow through with your self defence regardless of what happens. You're going to be surprised at first, how fast somone can close the distance on you.
Ultimately, the way you train will be the way you react. If real life exceeds the scope of your training, you will not react correctly. My $.02.
Jesse