Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created May 7, 2023 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengruppetta/a96d18fc81b6375518a1c1fd62956e08 to your computer and use it in GitHub Desktop.
Save stephengruppetta/a96d18fc81b6375518a1c1fd62956e08 to your computer and use it in GitHub Desktop.
import functools
import random
def roll_dice(max_value, number_of_dice):
return [
random.randint(1, max_value)
for _ in range(number_of_dice)
]
# Create a partial object that always rolls
# standard dice with 6 sides
roll_standard_dice = functools.partial(roll_dice, 6)
# Roll four standard dice
print(roll_standard_dice(4))
# Roll two standard dice
print(roll_standard_dice(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment