def diceroll(dicecount=1, dicesize=6, alwayslist=False): dicecount = int(dicecount) if dicecount == 1 and alwayslist == False: return genrandomnum(1, dicesize) else: resultlist = [] for i in range(dicecount): resultlist.append(genrandomnum(1, dicesize)) return resultlist
def randomnum(minimum, maximum): if isnumber(minimum): if isnumber(maximum): return genrandomnum(minimum, maximum) else: raise RuntimeError('Invalid Value (0016)') else: raise RuntimeError('Invalid Value (0016)')
def truthorliegame(): truthnum = genrandomnum(1, 4) if truthnum == 1: return 'Truth' elif truthnum == 2: return 'Maybe' elif truthnum == 3: return 'Maybe' return 'Lie'
def yesnogame(includemaybe=False): if includemaybe == True: maxnum = 3 else: maxnum = 2 afternum = genrandomnum(1, maxnum) if afternum == 1: return "Yes" elif afternum == 2: return "No" elif afternum == 3: return "Maybe"
def captcha(): tryanswer = '' numbervalues = { 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10 } numbertext = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten' ] if genrandomnum(1, 2) == 2: parta = randomitem(numbertext) else: parta = genrandomnum(1, 10) if genrandomnum(1, 2) == 2: partb = randomitem(numbertext) else: partb = genrandomnum(1, 10) tryanswer = input('CAPTCHA: What\'s ' + str(parta) + ' + ' + str(partb) + '? Your Answer (In Digits): ') if not bool(isinstance(parta, int)): parta = numbervalues[parta] if not bool(isinstance(partb, int)): partb = numbervalues[partb] try: tryanswer = int(tryanswer) except: return False return parta + partb == tryanswer
def psrgame(choice): choice = choice.lower() choices = { 'paper': 1, 'papers': 1, 'scissor': 2, 'scissors': 2, 'rock': 3, 'rocks': 3 } pcchoice = genrandomnum(0, 3) if pcchoice == choices[choice]: return 'Tie' elif pcchoice < choices[choice]: return 'Win' elif pcchoice > choices[choice]: return 'Loose'
def randchar(): while True: trychar = charlist[genrandomnum(1, len(charlist))] if len(trychar) == 1 and not (trychar in unwanted): return trychar
def randpassword(length): charstouse = string.ascii_letters + string.digits + string.punctuation newpass = '' for i in range(length): newpass += str(charstouse[genrandomnum(1, len(charstouse))]) return newpass