this is untested but should (more or less) do what you want
void randomSpawnNPC(int amt,int z)
{
/*
amt=total entities you want on the map
z=zone you want them on
*/
int i,mapW,mapH,entIndex;
string npcChr;
for(i=0;i<amt;i++)
{
//grab a random x,y cord for the entity
mapW=random(0,curmap.w);
mapH=random(0,curmap.h);
//grab a random NPC chr file to throw on the map
switch(random(0,5))
{
CASE 0: npcChr="0.chr"
CASE 1: npcChr="1.chr"
CASE 2: npcChr="2.chr"
CASE 3: npcChr="3.chr"
CASE 4: npcChr="4.chr"
CASE 5: npcChr="5.chr"
}
//check if the zone is proper
if(getZone(mapH,MapW)==z)
{
entIndex=EntitySpawn(mapW,mapH,npcChr);
EntitySetWanderZone(entIndex);
}
else i--;//if it's wrong try again (simply...)
}
}