コード例 #1
0
        p = sys.argv.index('-prob')
        ptemp = float(sys.argv[p + 1])
        prob = np.asarray(ptemp)
    if '-NSample' in sys.argv:
        p = sys.argv.index('-NSample')
        Nt = int(sys.argv[p + 1])
        if Nt > 0:
            NSample = Nt
    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)
    dice = random.Dice(NSample, p=prob)

    # create histogram of our data
    counts, bins = np.histogram(dice, bins=6)
    plt.bar([1, 2, 3, 4, 5, 6], counts / NSample)

    # plot formating options
    plt.xlabel('value')
    plt.ylabel('Probability')
    plt.title('random dice roll')

    plt.savefig('diceroll.png')

    # show figure
    plt.show()