private void getSpontaneousBivalents(int maxBivalents) {
        int firsth = 0;
        int secondh;
        while (firsth < popdata.ploidy-1 && bivalentcount<maxBivalents) {
            //search next spontaneous bivalent:
            while ( firsth<popdata.ploidy-1 && 
                    ( hsdone[firsth] ||
                        pairedWith[primaryside][firsth] != pairedWith[secondaryside][firsth] ) ) {
                firsth++;
            }
            if (firsth < popdata.ploidy-1) {
                //available firsth and secondh found so bivalent possible
                secondh = pairedWith[primaryside][firsth];
                assert(!hsdone[secondh]);
                addBivalent(firsth, secondh);
                hsdone[firsth] = true;
                hsdone[secondh] = true;
            }
            firsth++;
        } //while firsth, get spontaneous bivalents
    } //getSpontaneousBivalents