There are three instinctive human stress responses when bullets start to fly: fight, flight, or freeze. You should never do the latter as it leads to instant death, and only ever fight back if you're close enough or you have a gun, or something even bigger. In most civilian settings, the best option is to run – and fast.
Where and how you run is the key to staying alive. Head for the nearest point of hard cover, a wall for example, and from there your next move should be to figure out where the gunfire is coming from. Only then can you pick your safest escape route out of trouble.
Whenever you do run, be unpredictable. The clichéd advice is to sprint in a zig-zag motion, but that’s because it’s the best tactic available. You’re much harder to hit when moving in differing speeds and directions. Running in a straight line makes you an easy target.