If this is XP, right-click the My Computer icon and select Properties> Advanced tab> Startup & Recovery and UNCHECK the tick box for Auto Restart On System Failure. This may let you see an error code that wasn't visible since the rig was being told to restart.
If you aren't protecting your PC by running an uninterruptible power supply between it and the wall outlet to filter the current, power line noise and fluctuations can cause this.
If you have a fairly powerful PC, heat buildup or a cheap/failing/stressed power supply inside the case can cause this. Leaving the case open for a few days before moving on to the other steps is a very wise plan of action, since this can help you eliminate thermal issues from consideration.
Download MBM5 (Motherboard Monitor v5) and install it to see if the voltage from the various PSU rails is at or above specs.
If it is truly sporadic, and it does not increase in frequency during a typical session, then the problem may be a loose, dusty/corroded or damaged cable/connector/module/card.
Try removing the video card, memory modules and any PCI cards and reinstalling them. Just lift them out of their slot/socket and then push them firmly back into place. Ground yourself first and often during this by making contact with the case's PSU.
Unplug the IDE/floppy/power cables and reinstall each plug firmly but carefully.
If all this doesn't help, remove all but one RAM module and run MemtestX86 from a floppy to see if that RAM stick is failing. If there are no problems with it, and you have multiple sticks, shut down and replace that module with another and retest with Memtest.
As with any sort of machine, troubleshooting PC's involves following a logical set of steps to eliminate the most likely, most common problem before moving to the next likely cause, then negating that possibility. When you find the problem, you'll know it.