private void generateChiasma(int a, double chiasmaDist) {
        assert(!crossoverFinished);
        assert(!armFinished[a]);
        assert(slots.length==8);
        //select two of the four slots (chromatids) in this arm for chiasma formation:
        chromatid[0] = arm[a][rand.nextInt(2)];
        chromatid[1] = arm[a][2+rand.nextInt(2)];
        side = a % 2; //0=head in arm 0 and 2, 1=tail in arm 1 and 3
        /* note that:
         * (1-side) is the opposing side (tail=1 vs head=0)
         * the other arm of the same side is (a+2)%4
         */
        sideFact = side==0 ? 1.0 : -1.0; //multiplication factor to reverse directions
        //calculate position of new chiasma:
        if (Double.isNaN(lastpos[a])) {
            pos = chrom.getSidePos(side) + sideFact*distToFirstChiasma(chiasmaDist);
        }
        else {
            pos = lastpos[a] + sideFact*distToNextChiasma(chiasmaDist);
        }
        mindist = Double.NaN; //dist to nearest of two opposing chiasmata
        nearestArm = -1; //none yet
        if (!Double.isNaN(lastpos[oppoArms[side][0]])) {
            mindist = sideFact*(lastpos[oppoArms[side][0]]-pos);
            nearestArm = oppoArms[side][0];
        }    
        if (!Double.isNaN(lastpos[oppoArms[side][1]]) &&
            (Double.isNaN(mindist) || mindist>sideFact*(lastpos[oppoArms[side][1]]-pos))) {
                mindist = sideFact*(lastpos[oppoArms[side][1]]-pos);
                nearestArm = oppoArms[side][1];
        }
    } //generateChiasma