I modified and updated AK|Phantom's script into a mod for 0.5.18 and tweaked how it works and was considering further tweaks. If you haven't written your script already, I'd be happy to tweak this one further to also filter on breast size, skin tone, and butt size. I adjusted the code so adding additional conditions is much simpler.
Was thinking of going a step further to make it a little more optimized by caching the list of portraits and their attributes (refreshing every few minutes), so it's not redoing the directory listing and comparisons over and over. Since if you say, attack a bandit camp, right now that could generate 5-10+ characters and it'd re-scan the directory 5-10 times. Plus I'd like it to be a bit more advanced in it's pulling of attributes, like treat Brown as hair, but BrownSkin as skin color. Also to not match Elf races against DarkElf.
Anyways let me know, or if you can maybe mention any specific tagging you're already using I can tweak the mod ahead of time.
randomportrait mod Version 0.2 https://mega.nz/#!sXxmDAqZ!hmiE948bEroR3U2naD3vpNdnlVAh9Rfi2Ckf9l4YmDw
info.txt describes current rules i'm matching on. The contained code is also a bit easier to read/modify.