I only mention this because it's outside of what everyone else is saying, I'm betting it's the cable, but if you still have a problem after replacing the cables then consider this stuff.
You could also be experiencing a weak spring in the derailleur; or a problem with the shifter itself.
Did you check to make sure you don't have a broken or bent or worn ring gear tooth or teeth? Random could mean that as you pedal and you shift the ring gear has to be just in the right position where that tooth is to prevent a shift. Most cases this would act more like a skip, but not always. Or the shift ramps on the gear ring are worn which would not make the chain skip, just fail to pick up correctly.
Spin the pedals and look down at the chainrings, check to see if there is a wobble in the gears, they should run perfectly flat but if the chainring got bent a bit or the chainring bolts are loose, it could be a wobble causing sporadic shifting.