Violent off/on problem

OK, so sometimes when I driving the car "shuts off" (gauges drop, odo reads -------, but the engine is still 'running', just the loud pedal doesn't do anything), then it violently jumps back to life. It does this a few times. Sometimes the "Check fuel cap" light comes on, then next time it does it, the light comes off. I can never get it to do it for a mechanic and it doesn't happen at any specific time. What's this all about?