It's actually an easier written algorithm than you might think.

It's actually not a bad idea. There are already generic NPCs that don't have any particular depth to them. But enerating new NPCs isn't just about adding new people (that's the easy part), they also have to figure out:
1. What these NPCs do
2. Where they sleep and eat (this might involve actually changing a house's designation and the ownership of all the items)
3. How the towns perceive them (making additions to factions and such)
4. Their voice acting and dialogue (especially if they're replacing shop keepers/quest givers)
Overall it would be a major over-haul to the game, and one that I seriously doubt Bethesda would undertake. There's also the fact that these attacks will inevitably become tedious. Bethesda realized the same thing happened with some Dragon attacks (which is why they have been altered slightly with different patches).
I personally like the idea of Vampire attacks (and I thought they were awesome the first time they happened). I can personally think of some different fixes:
- Make them attack the town gate instead of inside the town (so only guards are in danger). You can be alerted to this if you fast travel to a town.
- Make NPCs run for cover when vampires come in (though this may not be very reliable because if the vampire still perceives them as an enemy they can still easily kill them)
- Make the vampires specifically target the player. This can be done by initiating dialogue with the Dragonborn before attacking or something.
- No town attacks before starting Dawnguard quest line, and stopping them (but still maybe leaving some Vampire ambushes in the wilderness) after you're done.