import random
import decimal


def generate_float(i_len=None, f_len=None, integer_allowed=True, max_val=None,
                   fixed_f_len=False, i_min=None):
    """
      Generates random float with floating number of digits in integer and
    fractional part. Fractional part length can be fixed for e.g. money types.
      Cannot be used with f_len=1 & fixed_f_len=True - fraction part will be 0
    :param i_len: max length of integer part
    :param f_len: max length of fraction part
    :param integer_allowed: whether float might end with zero like 21.0
    :type max_val: int or None
    :param max_val: max allowed value, result will be generated up to the value
      specified (never equal)
    :param fixed_f_len: whether length of floating part is fixed
    :param i_min: min value of integer part, default value is 0
    """
    f_len = 6 if f_len is None else f_len
    i_max = max_val or 10 ** (3 if i_len is None else i_len)
    f_max = 10 ** f_len
    f_min = 0 if integer_allowed else 1
    i_min = i_min or 0
    i_part = random.randint(i_min, i_max - 1)
    f_part = random.randint(f_min, f_max - 1)

    if fixed_f_len and f_part % 10 == 0:
        f_part += random.randint(1, 9)

    return float(i_part + f_part / decimal.Decimal(f_max))