Skip to content

Instantly share code, notes, and snippets.

@sgodfrey66
Last active March 11, 2019 19:54
Show Gist options
  • Save sgodfrey66/d6faddf65e1f10deacdcf8cc962254eb to your computer and use it in GitHub Desktop.
Save sgodfrey66/d6faddf65e1f10deacdcf8cc962254eb to your computer and use it in GitHub Desktop.
# Simulate game
n_sims = 10_000
game_record = []
for i in range(n_sims):
# Simulate two dice rolls
rolls = np.random.randint(1,7,2)
# Sum the two dice
sum = rolls.sum()
# Simulate drawing sum cards from a deck without replacement
cards = np.random.choice(np.arange(1,53),size = sum, replace = False)
# Calculate payout
payout = 0
for card in cards:
# Ace
if card in [1, 14, 27, 40]:
payout += 25
# King
elif card in [13, 26, 39, 52]:
payout += 2
# other cards
else:
payout += 0
game_record.append(payout)
print("Average Payout: $%.2f" % (np.sum(game_record)/n_sims))
ax = sns.distplot(game_record, kde = False)
plt.title("Histogram of 10,000 simulated game plays");
ax.set_xlabel("Payout")
ax.set_ylabel("Count");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment