import random
import math
from xdict import utils
#####
def gen_random_ascii_chr():
    return(chr(math.floor(random.random() * 256 + 1) % 256))

def gen_random_ascii_str(length):
    rslt = ""
    for i in range(0,length):
        rslt = rslt + gen_random_ascii_chr()
    return(rslt)


def gen_random_str_of_length(length,**kwargs):
    '''JZ._$'''
    if('char_set' in kwargs):
        char_set = kwargs['char_set']
    else:
        char_set = "0123456789abcdefghijklmnopqrstuvwxyz"
    rslt = ''
    for i in range(0,length):
        seq = math.floor(random.random()*36+1) % 36
        c = char_set[seq]
        rslt = rslt + c
    return(rslt)



######
def gen_random_word(**kwargs):
    if('max_word_length' in kwargs):
        max_word_length = kwargs['max_word_length']
    else:
        max_word_length = 10
    length_range = random.randrange(max_word_length+1)
    if('char_set' in kwargs):
        char_set = kwargs['char_set']
    else:
        char_set = 'abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ'
    if('fixed_word_length' in kwargs):
        length_range = kwargs['fixed_word_length']
    else:
        pass
    len = char_set.__len__()
    word = ''
    for i in range(length_range):
        word = ''.join((word,char_set[random.randrange(len)]))
    return(word)

def gen_random_root():
    rand_num = random.randrange(3)
    if(rand_num == 0):
        return({})
    elif(rand_num == 1):
        return([])
    elif(rand_num == 2):
        return(())
    else:
        return({})

def gen_random_type_via_ratio(**kwargs):
    if('d' in kwargs):
        rd = kwargs['d']
    else:
        rd = 0
    if('l' in kwargs):
        rl = kwargs['l']
    else:
        rl = 0
    if('t' in kwargs):
        rt = kwargs['t']
    else:
        rt = 0
    if('s' in kwargs):
        rs = kwargs['s']
    else:
        rs = 0
    if('v' in kwargs):
        rv = kwargs['v']
    else:
        rv = 0
    if((rd+rl+rt+rs+rv) == 0):
        rd = 1
        rl = 1
        rt = 1
        rs = 1
        rv = 1
    total = rd + rl + rt + rs + rv 
    rand_num = random.randrange(1,total+1)
    bd = rd + 1
    bl = bd + rl
    bt = bl + rt
    bs = bt + rs
    bv = bs + rv
    if(rand_num in range(1,bd)):
        return('d')
    elif(rand_num in range(bd,bl)):
        return('l')
    elif(rand_num in range(bl,bt)):
        return('t')
    elif(rand_num in range(bt,bs)):
        return('s')
    elif(rand_num in range(bs,bv)):
        return('v')

def gen_random_depth(min_dep,max_dep):