Irregular Periods

Why do I keep having irregular periods? I'm not having sex, so I'm pretty sure I'm not pregnant. The doctor told me that my cycle was about to start seconds after she checked me, but that was 7 days ago. This happens to me about once every 2-3 months and it's so annoying. I always run out of pads and stuff because I'm scared it might happen while I'm unprepared. What can I do?