There is a tutorial going into more detail about this type of ...
Tutorial: Creating a random object in a particular category