Static NPCs: NPCs will Spawn in locations such as where you start, in the Refugee Center, and other places that mods state they should spawn (I am not aware of a third place they spawn in Vanilla).
Random NPCs: Spawn according to the Random NPC Spawn Rate. They tend to be rather rare, and when you do encounter them are generally reasonable unless you look like a mutated bio-freak, in which case they tend to be terrified of you. Other times you’ll get ones who are just straight up unreasonable. Some will tell you to drop your weapon and then start trusting you, or tell you to leave, or maybe just attack you then and there. Diplomacy can also lead to getting attacked.
Very rarely you’ll get one who says “This is my Territory, Fucker” or something like this, and will refuse further conversation with you. These idiots don’t seem to take into account how powerful you might be (A heavily armed, and armored, post-thresh Chimera didn’t seem to deter one in the slightest).
Note that as soon as an NPC is Hostile or becomes terrified of you, there is literally no reasoning with them.
That being said, NPCs can be recruited, and there’s a noticeable difference between being alone and having an NPC helping you when zombie bashing. If you can, see what an NPC can do. In my current game, I found an NPC with an AR-15 the moment I escaped the Lab and she’s been with me ever since. She’s proved an invaluable ally.
Also, I have never, EVER encountered an NPC while sleeping.