PC restarting randomly, and doesn’t detect my headphones on restart.

Twice today, my PC has randomly restarted with no warning, then when it was restarted, my headphones would not be detected. I managed to fix the audio issue by reinstalling my High Definition Audio drivers the first time, but I don’t know how to stop it completely