Only way you will fix it is if it stays broken or you can catch it farting around . Id get a can of Starting Fluid from your local parts store . When it does it again , crank the engine and have someone shoot some starting fluid in the air filter and or intake . If it fires on that but wont run you have a fuel problem . I had a old Nissan Sentra that would do the same thing . It wouldnt fire when someone else drove it but when I tried it later the engine would fire right up . One day it finally didnt fire on me and I got to do some trouble shooting . I removed a fuel line and found no fuel flowing / pressure . I went around and smacked the fuel tank on the bottom with my hand and the pump started chugging and spit out a shot of fuel before the key was shut off .
You could very well have a pump that is fine when checked but hangs when it feels like it . My mothers Jeep did the same crap but only when it was hot and had to replace the computer because it wasnt sending out voltage to the crank sensor when the computer got hot .
Yours is doing it hot or cold . Also if you can find the schrader valve on the fuel injector rail , and the engine dosent start , push the core in ( like a tire valve if you didnt know ) and see if it shoots a little fuel out . During cranking the fuel pressure should build up in the rail , unless the pump is down or the electronics are not firing the pump up for some reason . Next step if the pump isnt working is to bypass the pump relay so that you bypass the electronics end . If the fuel still dosent flow , the pump is the culprit if it does there is other trouble ( or the pump just chose to unstick ) .
Best thing you can do is listen real close for the fuel pump when you turn the key on . Should hear a buzzing noise from the tank area when the key is turned on for a few seconds . It should also buzz when the engine is cranked but may be hard to hear .
Like I said , if it breaks for good you can find it . If not you got to trick it into telling you whats broken .
Try the starting fluid first , the engine should fire or attempt to fire on the fluid . If it wont fire on the fluid or try to then there could be a problem elsewhere (coil , wiring , computer , crank sensor , etc.) .
Im betting your pump is sticky and kicks in when it wants to or the relay for it is sticking . Good luck and keep us updated .