Last active
July 2, 2022 00:38
-
-
Save Lubba-64/04325340d452576f8a350b549939f2f7 to your computer and use it in GitHub Desktop.
Dice roll probability sim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
print( | |
""" | |
This script simulates this scenario: | |
you have a die of N faces | |
you have Y quantity of that die | |
what is the average of X rolls, | |
taking the highest value of all | |
dies for that roll? | |
""" | |
) | |
sides = int(input("Enter the number of die faces: ")) | |
advantage = int(input("Enter the number of dice to roll")) | |
rolls = int(input("Enter the number of simulations: ")) | |
sum_ = 0 | |
for i in range(rolls): | |
sum_ += max([random.randrange(0, sides) for x in range(advantage)]) | |
res = sum_ / rolls | |
print(f"The expected value is: {res}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by Matt Parker.
made in 5 minutes.