I've used similar in the past. I'd suggest to add a check for the NPC with the highest HP - even though there's an NPC next to with with 1 hp, that's not the best choice if there's one 2 blocks away @ full hp
Also,the way you are iterating through the arraylist of local NPC's you will find a pattern it will attack by. Such as if you're surrounded by NPC's it will always attack the east one or something.
Once you find an NPC that is closer than the previous, add it to a list. If the next NPC is the same distance away, add it to the list, repeat.
Once you iterate through all of them, chose a random NPC from the list.