Before you change the distributor may I ask how many miles on your vehicle? Sounds like you may be having the classical "cut out" and I'd recommend new cap, rotor, wires and see if that fixes the problem.
ON my 88 and sure on the post 90 4.0s it teh same way. There is a hall effect sensor in the distributor to "fire" the injectors. This sensor is called the sync sensor or the Camshaft position sensor.
There is a sensor on the bellhousing called the crankshaft position sensor (CPS). It determines when the spark plugs fire. The CPS is a part that does wear out even though it done not make physical contact. It is very similar to the ABS sensor on any vehicle.
Yes, you can use a rebuilt from the parts store but I purchased a new distributor for my 88 XJ from the dealership. I wanted a "new" sync sensor in my replacement distributor so i spent the extra money.
You also may want to make sure the hose from the throttle body to the MAP sensor is not borken. If you unhook the MAP sensor it runs bad - don't ask me how I know
So I may do things in this order
1) Cap, rotor, wires
2) new CPS, just replace it if it has over 100K on it
3) new MAP sensor, same as CPS for mileage
4) replace distributor