Most of the time, this type of problem is caused by battery cable terminals which have become infiltrated by almost invisible corrosion. The solution is to buy a tapered reamer type battery cable service tool, disconnect both battery cables, and use it to scrape the battery posts and the inside surface of the cable clamps (the reamer end of the tool must be inserted from the bottom side of the clamps, and turned 1/2 to 1 turn clockwise) until they have a shiny ring around them. Then tighten the clamp bolts until the cables cannot be moved by hand pressure.
If your car has an automatic transmission; this can be caused by a failing neutral safety switch. This switch prevents the starter from running unless the shifter is in Neutral or Park. Next time the car does not start; try moving the shfter to Neutral and seeing whether it starts in that position. If this fixes it repeatedly; either use this as a new starting method; or replace the neutral safety switch.
If your car has a manual transmission; there is a switch on the clutch pedal linkage called the clutch pedal position switch; which prevents the starter from running unless the clutch pedal is pressed all the way down. This switch can go bad; or may need to be adjusted. Sometimes, a thick carpet on the floorboards will prevent the clutch pedal from moving far enough down to trigger the switch.
There is also a possibility that the ignition starter switch may be failing; but that is less likely than the above issues.