From my understanding C. elegans are mainly hermaphrodites but are occasionally males to increase genetic variation. Why is it that random females aren't born instead to achieve he same goal (genetic diversity)?
The evolution of self-fertile hermaphrodites is thought to be a specialization that occurred several times in the nematoda. For example, most of small, free-living soil nematode species related to C. elegans are male/female. C. briggsae, which last shared a common ancestor 80 myr ago is also male/hermaphrodite, but I believe their ancestor is thought to have been male/female. At the developmental level, the first germ cells to mature in the somatic gonad develop as sperm and then the Germline switches over to make oocytes.
C.elegans makes use of an X0 sex determination system, so there is only one sex chromosome (X), which only allows for two sexes (XX and X0) as 00 is not viable.