It's all in the preparation:
1. Train your situational awareness.
As soon as the first shot is fired, you need to be the FIRST one to realize what's going on. You need to be the first person to know which direction the shot is coming from, and you need to already know where the nearest exit and places of cover are. If you can do this, you are already faring better than 99% of the people around you.
2. Train your instinctive reactions.
You need to run drills. Practice diving/rolling/jumping to points of cover, or otherwise getting your body to cover as quickly as humanly possible. Practice dropping everything in your hands, drawing your weapon (if you have one,) and dropping into a prone position. Practice turning away from a certain point (the shooter) and running… I know it sounds stupid, but if you're in a panic you might trip over your own feet trying to run away. You have to make sure that when your body hits that fight-or-flight point, it knows how to respond. Untrained people might instinctively cover their face, or run around in circles, or even worse, completely freeze.
3. Have a reasonable EDC, and practice using it.
This goes without saying, but there are several things that can help you here:
- a firearm
- a bulletproof vest
- a knife
- other weapons (taser, baton, etc.)
If you're not legally able to carry these things, you're out of luck, but if you're seriously concerned about a shooting you may want to see what you CAN get.
4. Avoid places where a shooting might occur.
This is probably the most important thing you can do - just don't go into seedy neighborhoods, or shady poor-people department stores, or crappy back-road gas stations late at night. It's not plausible to believe you can avoid EVERY place where there may be a shooting, and many shootings happen in perfectly nice places, but don't tempt fate.