Fuel pump not always turning on

My 2001 Oldsmobile Alero only starts about 50% of the time and has also turned off twice when I was driving, once in a parking lot and once when I was stopped at an intersection. It cranks and the radio and lights work. The fuel pump was replaced two years ago and sometimes you can hear the pump turn on and sometimes you can’t. My husband replaced the fuel pressure regulator and has switched out the fuel pump relay but it hasn’t fixed the problem. Based on this, can you tell whether the fuel pump might need to be replaced again or whether it could be something else connected to the fuel pump, or something else entirely? The fuel pump is under warranty at the dealership that replaced it, but unless the fuel pump is bad then I don’t want to go back to this dealership and would rather go to different repair shop. Thanks!

Since it happens a lot, maybe hotwire a 12V bulb across the fuel pump and put it someplace where you can see it at a glance.
When it stalls and refuses to start, look at the bulb and see if it is lit.
If it isn’t lit, the problem is not your fuel pump but whatever drives it.
If it is lit and you don’t hear your pump running, the pump is likely at fault.

You could look at the bulb when it is stalling to see if it stays lit but you’d have to be quick: a car’s computer usually turns off the pump when the engine stops turning for safety reasons. Unless the car gives you some indication it is about to stall (like sputtering, for instance), it would be difficult to see if the car stopped turning because the pump turned off or the pump turned off because the car stopped running - a classic ‘chicken and egg’ conundrum.

The above may not be a perfect test but could help you at least eliminate culprits.