Right. Basically, it's random chance but by no means pure chance or equal chance. Stuff you do CAN increase your odds.
When the zombie brak the door, they start attacking random villager until a sufficient number ( equal to your home defence, noramlly) attack you, then kill you.
If this is true, it is in stark contrast to what everyone has been saying on the forums, and much closer to what I've been arguing.
Zombies are distributed as stated above - one zombie chooses random villager, next zombie chooses random villager. Statistically you will get a number of zombies evenly distributed between citizens, but due to the vagaries of the RNG some will get more, some will get less. It doesn't stop at the home defense number - I've seen people with bedrolls get dogpiled by 9 zombies, while the rest of us get 1-2 each.
There are several possibilities:
1) There are enough zombies that make it through the defenses that everybody gets more zombies than their house can defend against. i.e. 200 zombies make it through, there are 4 of you, you get 50 zombies average each. Even if one has a fort (8 defense+4 defense items=12 defense) if you all get 40-50 zombies each, defense doesn't matter, you all die. There is still a vanishingly small chance that fort guy gets 11 zombies while the rest of you get 60 each.
2) Just enough zombies get through the gate that there is an increased chance of survival for those with higher defenses. For example, there are 4 of you in town, and 40 zombies make it through. Someone has a fort (8+4=12 defense) while the rest of you are in hovels (4+4=8 def). If the zombies are evenly distributed, fort guy lives, the rest of you die. There is still a chance that fort guy gets 20 zombies, and the other three gets 3-4 each. Still, the odds are stacked against the other three.
3) The number of zombies that get through the gate is less than the number of citizens in town. In this case you see 1 zombie per citizen, although an unlucky few get 2-3 each. Anything higher than a tent will almost guarantee survival here.
From the point of view of a survivor it looks really random, but it's just the RNG.
Also, each corpse you leave in the town (did not use water to destroy the corpse or drag it out of town) will instakill one citizen come the attack, regardless of defense.
The only thing that assures LMS is if you survive till the next night. If everyone dies, regardless of number of zombies or defenses, then LMS is awarded randomly among the people who "died in their bed" (i.e. you might have more zombies on you, but they were saving you for dessert).