# -*- coding: utf-8 -*-"""This is a very simple "dice rolling" module for python. It uses thenormal random number generator to generate random numbers in therange from 1 to /sides/.It also provides shortcuts to the d4, d6, d10, d20 and d100. Youalso can call ndX to get a list of n rolls of an X sided dice. - Tobias Diekershoff <tobias.diekershoff--at--gmx.net> released under a Creative Commons License CC-BY-3.0Versions 0.1 TD 2009-FEB-25 initial set of dices"""import random
defdice(sides):
"""Rolls the dice - IOW returns a random number up to sides"""return random.randint(1,sides)
defd4():
"""Rolls a d4"""returndice(4)
defd6():
"""Rolls a d6"""returndice(6)
defd10():
"""Rolls a d10"""returndice(10)
defd20():
"""Rolls a d20"""returndice(20)
defd100():
"""Rolls a d100"""returndice(100)
defnd4(n):
"""Rolls n times a d4 and returns the result as a list"""
r = []
for i inrange(0,n):
r.append(d4())
return r
defnd6(n):
"""Rolls n times a d6 and returns the result as a list"""
r = []
for i inrange(0,n):
r.append(d6())
return r
defnd10(n):
"""Rolls n times a d10 and returns the result as a list"""
r = []
for i inrange(0,n):
r.append(d10())
return r
defnd20(n):
"""Rolls n times a d20 and returns the result as a list"""
r = []
for i inrange(0,n):
r.append(d20())
return r
defnd100(n):
"""Rolls n times a d100 and returns the result as a list"""
r = []
for i inrange(0,n):
r.append(d6())
return r
defndices(n,s):
"""Rolls n times a dice with s sides"""
r = []
for i inrange(0,n):
r.append(dice(s))
return r