Skip to content

Instantly share code, notes, and snippets.

@Lubba-64
Last active July 2, 2022 00:38
Show Gist options
  • Save Lubba-64/04325340d452576f8a350b549939f2f7 to your computer and use it in GitHub Desktop.
Save Lubba-64/04325340d452576f8a350b549939f2f7 to your computer and use it in GitHub Desktop.
Dice roll probability sim
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}")
@Lubba-64
Copy link
Author

Lubba-64 commented Jul 2, 2022

Inspired by Matt Parker.

made in 5 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment