it could be almost anything - bad hard drive / motherboard / memory / PSU / overheating.......even a virus.
When the machine restarts keep tapping the F8 key, and from the menu choose the option which reads something like "do not restart on system failure"
Next time if goes wrong it shouldn't reboot, but should leave an error message on screen. Give us the ENTIRE message including any STOP! warnings