And it seems to be totally random?
I would make a new fresh ground for the battery, maybe multiple, onto the frame. What year/model/etc is the truck?
2002 Red Mazda B2300
Short Cab, Short Bed, Pioneer sound system:
DEH-P5100UB deck, dual USB/aux inputs, single CD, organic display, remote
4 TS-A6872R 40 watt nominal speakers
2 TS-SW2501S4 250 watt nominal 10" subwoofers