Skip to content

Instantly share code, notes, and snippets.

@JanSchm
Created January 3, 2023 15:32
Show Gist options
  • Save JanSchm/439d0b83efe4430390e539b809057b02 to your computer and use it in GitHub Desktop.
Save JanSchm/439d0b83efe4430390e539b809057b02 to your computer and use it in GitHub Desktop.
import random
# Define the probability distribution for the dice roll
# Each number has an equal probability of being rolled
probability_distribution = [1, 2, 3, 4, 5, 6]
# Set the number of simulations to run
num_simulations = 20000
# Initialize a list to store the results of the simulations
results = []
# Run the simulation
for i in range(num_simulations):
# Generate a random sample from the probability distribution
result = random.choice(probability_distribution)
# Add the result to the list
results.append(result)
# Calculate the frequency of each outcome
outcome_frequency = {}
for outcome in probability_distribution:
outcome_frequency[outcome] = results.count(outcome)/num_simulations
print("Simulation results:")
for outcome, freq in outcome_frequency.items():
print(f"{outcome}: Occurrence {freq * 100:.2f}% ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment