Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
n_rolls = 10000000
n_sides = 20
min_dice_value = 8
rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1
rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1
print('-' * 30)
print('advantage of disadvantages')
print("simulation:", np.mean(np.maximum(rolls_1.min(axis=1), rolls_2.min(axis=1))
>= min_dice_value))
print('-' * 30)
print('disadvantage of advantages')
print("simulation:", np.mean(np.minimum(rolls_1.max(axis=1), rolls_2.max(axis=1))
>= min_dice_value))
print('-' * 30)
print('single roll')
print("simulation:", np.mean(rolls_1[:, 0] >= min_dice_value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.