What causes headlights to shut off randomly?

This could be caused by a number of reason's , The first thing I would check is to make sure my battery is sucure and can't slide over and ground out the hot post.The second thing I would check is to see if the wire from my headlight's to my battery's hot wire is getting a good conection(I have had both problem's in older vechile's)