Each mob you kill has an X percentage chance of the next one being a boss, so it's basically a bit of luck.