Connection between generation number and anomaly cancellation in supersymmetric models