コード例 #1
0
def Cookie_Derp(Seedd, Ratee, Nmeass, Nexpp, OutputFileNamee):
    # default seed
    Seed = 5555

    # default rate parameter for cookie disappearance (rate =1, means a cookies per day)
    Rate = 1

    # default number of time measurements (time to next missing cookie) - per experiment
    Nmeas = 1

    # default number of experiments
    Nexp = 1

    # output file defaults
    doOutputFile = False

    # class instance of our Random class using seed
    Seed = int(Seedd)
    Rate = float(Ratee)
    Nmeas = int(Nmeass)
    Nexp = int(Nexpp)
    random = Random(Seed)
    doOutputFile = True
    
    if doOutputFile == True:
        OutputFileName = OutputFileNamee 
    else:
        OutputFileName = "Cookie.txt"

    if doOutputFile:
        outfile = open(OutputFileName, 'w+')
        outfile.write(str(Rate)+"\n")
        for e in range(0,Nexp):
            for t in range(0,Nmeas):
                outfile.write(str(random.Exponential(Rate))+" ")
            outfile.write(" \n")
        outfile.close()
    else:
        print(Rate)
        for e in range(0,Nexp):
            for t in range(0,Nmeas):
                print(random.Exponential(Rate), end=' ')
            print(" ")
コード例 #2
0
        Nt = int(sys.argv[p + 1])
        if Nt > 0:
            Nmeas = Nt
    if '-Nexp' in sys.argv:
        p = sys.argv.index('-Nexp')
        Ne = int(sys.argv[p + 1])
        if Ne > 0:
            Nexp = Ne
    if '-output' in sys.argv:
        p = sys.argv.index('-output')
        OutputFileName = sys.argv[p + 1]
        doOutputFile = True

    # class instance of our Random class using seed
    random = Random(seed)

    if doOutputFile:
        outfile = open(OutputFileName, 'w')
        outfile.write(str(rate) + " \n")
        for e in range(0, Nexp):
            for t in range(0, Nmeas):
                outfile.write(str(random.Exponential(rate)) + " ")
            outfile.write(" \n")
        outfile.close()
    else:
        print(rate)
        for e in range(0, Nexp):
            for t in range(0, Nmeas):
                print(random.Exponential(rate), end=' ')
            print(" ")
コード例 #3
0
ファイル: CoinToss.py プロジェクト: rjscott29/PHSX815_Week2
        doOutputFile = True

    # class instance of our Random class using seed
    random = Random(seed)

    if doOutputFile:
        outfile = open(OutputFileName, 'w')
        if Bern:
            for e in range(0, Nexp):
                for t in range(0, Ntoss):
                    outfile.write(str(random.Bernoulli(prob)) + " ")
                outfile.write(" \n")
        if Exp:
            for e in range(0, Nexp):
                for t in range(0, Ntoss):
                    outfile.write(str(random.Exponential()) + " ")
                outfile.write(" \n")
        if Dice:
            for e in range(0, Nexp):
                for t in range(0, Ntoss):
                    outfile.write(str(random.Diceroll(sides)) + " ")
                outfile.write(" \n")
        outfile.close()
    else:
        if Bern:
            print("---Bernoulli---\n")
            for e in range(0, Nexp):
                for t in range(0, Ntoss):
                    print(str(random.Bernoulli(prob)) + " ")
                print(" \n")
        if Exp: