A computer shutting down randomly can be a sign of many different things. It could be overheating, a virus, bad drivers, faulty PSU or bad RAM.
You can try sticking a desktop fan right on the computer with its side case off.
A virus is an easy fix. Download the necessary anti-virus software and run it.
The RAM is easy to diagnose. Download and run memtest. For the PSU, you just have to do what is suggested and swap it with another.