import string
import random


def generate_keyword(chars=None, k_length=None):
	"""
	Generate keyword for annotators and batches.

	Args:
		chars (str): type of characters used to generate keyword, 
				*default:* ``string.ascii_letters+string.digits``
		k_length (int): length of the keyword, *default:* ``random.randint(8,12)``
	
	Returns: 
		str: generated keyword

	Examples:
		>>> generate_keyword()
		'WfgdmWPZ7fx'
		>>> generate_keyword(chars=string.digits)
		'15151644097'
		>>> generate_keyword(chars=string.ascii_letters, k_length=3)
		'RIF'
	"""

	# set default for chars and k_length if they are not defined
	if not chars:
		chars = string.ascii_letters+string.digits
	if not k_length:
		k_length = random.randint(8,12)

	return ''.join(random.choice(chars) for x in range(k_length))