Spontaneous fluxoid formation in superconducting loops