How is horse race post position determined?

It's either randomly drawn, or the names are randomly drawn and the trainers get to pick what position they want in the order their horse's name is drawn.