Spontanious severe cramping...

I had major cramping problems in the early race season when I would get toward the end of a race and had been pushing at my max. I also experienced them while training / riding at a hard effort when I was tired and not recovered from racing or hard riding the days prior. The first thing I changed was to not push hard every day. Steady, easy mileage some days, and one or two hard efforts per week was a key. Steady means: Ride at a pace where you can carry on a converstion without getting out of breath.
The other key was hydration and as important for me was a calcium / magnesium supplement (suggested daily requirement) about 1/2 hour before going to sleep at night.
I don't claim to be an expert; these things worked for me. I also want to say that if I ride long distance, above my conditioning, I will still occasionally get cramps, at that point I back way off, spin lightly or stop briefly and stretch, and when they subside, keep going.
The more rested and condtioned I am the cramps do not happen.