It could one of many things:
When you have trouble starting your car, do you get spark? (If no, then it could be a bad distributor, wires, plugs, starter, battery, coil, etc.)
Does it crank good and hard to try to turn over but just doesn't? Like there is plenty of juice, but just no luck? (If you are getting spark and the car tries to turn over but just won't, it could be your main relay [which happened to me], fuel filter, fuel pump and/or fuels pump screen, collapsed or clogged fuel lines, still possibly a bad coil, spark plug wires could be loose or dirty, or spark plugs themselves.)
Also make sure to check other things that are often overlooked as well. Some cars that have alarms installed on them have a kill switch as well and if you accidentally unknowingly activate the kill switch, you won't be able to start the car. Other little things like, clogged air intake tubes or stock air boxes full of so much stuff your car doesn't get enough air to start.
Since there are times that you can start your car still, I would rule out the kill switch idea and most likely isn't a clogged air box either. Check out a couple of my other threads relating to starting issues and the main relay.
92 Si mystery. Starts some times, not others, no one can figure out the problem
Good luck in your diagnosis. I hope my info helped a little.