draws eccentricities appropriate to given periods, generated according to empirical data from Multiple Star Catalog

def draw_eccs(n,per=10,binsize=0.1,fuzz=0.05,maxecc=0.97):
    """draws eccentricities appropriate to given periods, generated according to empirical data from Multiple Star Catalog
    """
    if np.size(per) == 1 or np.std(np.atleast_1d(per))==0:
        if np.size(per)>1:
            per = per[0]
        if per==0:
            es = np.zeros(n)
        else:
            ne=0
            while ne<10:
                mask = np.absolute(np.log10(MSC_TRIPLEPERS)-np.log10(per))<binsize/2.
                es = MSC_TRIPDATA.e[mask]
                ne = len(es)
                if ne<10:
                    binsize*=1.1
            inds = rand.randint(ne,size=n)
            es = es[inds] * (1 + rand.normal(size=n)*fuzz)
    else:
        longmask = (per > 25)
        shortmask = (per <= 25)
        es = np.zeros(np.size(per))

        elongs = MSC_TRIPDATA.e[MSC_TRIPLEPERS > 25]
        eshorts = MSC_TRIPDATA.e[MSC_TRIPLEPERS <= 25]

        n = np.size(per)
        nlong = longmask.sum()
        nshort = shortmask.sum()
        nelongs = np.size(elongs)
        neshorts = np.size(eshorts)
        ilongs = rand.randint(nelongs,size=nlong)
        ishorts = rand.randint(neshorts,size=nshort)

        es[longmask] = elongs[ilongs]
        es[shortmask] = eshorts[ishorts]

    es = es * (1 + rand.normal(size=n)*fuzz)
    es[es>maxecc] = maxecc
    return np.absolute(es)