Game Utils v1.0
This commit is contained in:
17
dice.py
Normal file
17
dice.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import random as rd
|
||||
from . import serializable
|
||||
|
||||
class Dice(serializable.Serializable):
|
||||
def __init__(self, seed=42):
|
||||
self.seed = seed
|
||||
rd.seed(self.seed)
|
||||
|
||||
def roll(self, num_faces=20):
|
||||
return rd.randrange(start=1, stop=num_faces+1, step=1)
|
||||
|
||||
def head_or_tails():
|
||||
result = rd.randint(0,1)
|
||||
if result: # true
|
||||
return "head" # face
|
||||
else:
|
||||
return "tails" # pile
|
||||
Reference in New Issue
Block a user