Enemy gen?

How do i program random enemy geneation and ristrict it so they only appear in some areas? Like a mask or sompthing?