A few questions
Which motherboard, CPU and other hardware are you using Or PC make and model?
Did you change anything just before this started to happen?
What are you usually doing when it would randomly switch off?
Have you tried unplugging everything from the motherboard (e.g hard disks, graphics card if you have on board, fans except CPU fan, optical drives) and leave on one stick of RAM (if you have more than one RAM stick, test with both separatly. Then tried turning it it on? If the problem still persist, you have ruled out everything excep the motherboard, CPU and PSU.