We do not completely understand this process either in the sun or in the earth, BUT one of the prevailing theories called the Parker Dynamo Theory predicts that in a rotating, conductive system where magnetic fields are subject to 'cyclonic convestion', you end up with field flips with a time interval that depends on the density, conductivity and rotation rate of the system. I am not an expert in this area, but at least there is a theory to start from that SEEMS to explain some of this, and it works for both the sun and the earth! But there are many unsettled issues about just how the magnetic field is generated in the first place, and several observations that do not support this theory very well.
All answers are provided by Dr. Sten Odenwald (Raytheon STX)
NASA IMAGE/POETRY Education and Public Outreach program.