Added bananarandom

This commit is contained in:
itec78 2020-08-31 22:36:10 +02:00
parent 081eaeb01d
commit 4ac67ffa83
2 changed files with 39 additions and 0 deletions

View file

@ -41,6 +41,32 @@ def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None):
return(v)
def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary = None):
import random
#defaults
if dictstart is None: dictstart = 0
if shiftend is None: shiftend = 0
if minlength is None: minlength = 6
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")]
numdict = len(dictionary)
st = ""
l = 0
i = (numdict - 1 + dictstart + shiftend) % numdict
while not (i == (numdict - 1 + dictstart) % numdict and l >= minlength):
r = random.randint(0, len(dictionary[i]) - 1)
st = dictionary[i][r] + st
i = (i - 1) % numdict
l += 1
return(st)
if __name__ == "__main__":

13
bananarandom.py Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env python3
import argparse
import banana
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate random banana")
parser.add_argument("--dictstart", help="Set starting dictionary", type=int)
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int)
parser.add_argument("--minlength", help="Set minimum length", type=int)
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
args = parser.parse_args()
print(banana.bananarandom(args.dictstart, args.shiftend, args.minlength, args.dictionary))