コード例 #1
0
ファイル: CoinToss.py プロジェクト: rjscott29/PHSX815_Week2
 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:
         print("---Exponential---\n")
         for e in range(0, Nexp):
             for t in range(0, Ntoss):
                 print(str(random.Exponential()) + " ")
             print(" \n")
コード例 #2
0
ファイル: Diceroll.py プロジェクト: Raxxak/PHSX815_Week2
    if '-seed' in sys.argv:
        p = sys.argv.index('-seed')
        seed = sys.argv[p + 1]
    if '-prob' in sys.argv:
        p = sys.argv.index('-prob')
        ptemp = float(sys.argv[p + 1])
        if ptemp >= 0 and ptemp <= 1:
            prob = ptemp
    if '-Ntoss' in sys.argv:
        p = sys.argv.index('-Ntoss')
        Nt = int(sys.argv[p + 1])
        if Nt > 0:
            Ntoss = Nt
    if '-Nexp' in sys.argv:
        p = sys.argv.index('-Nexp')
        Ne = int(sys.argv[p + 1])
        if Ne > 0:
            Nexp = Ne

    # class instance of our Random class using seed

    random = Random(seed)

    for e in range(0, Nexp):
        result_array = []
        for t in range(0, Ntoss):
            #print(random.Bernoulli(prob), end=' ')
            result.write(str(random.Diceroll(prob)) + "\n")

    result.close()