<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def generate_random_perovskite(lat=None):
    '''
    This generates a random valid perovskite structure in ASE format.
    Useful for testing.
    Binary and organic perovskites are not considered.
    '''
    if not lat:
        lat = round(random.uniform(3.5, Perovskite_tilting.OCTAHEDRON_BOND_LENGTH_LIMIT*2), 3)
    A_site = random.choice(Perovskite_Structure.A)
    B_site = random.choice(Perovskite_Structure.B)
    Ci_site = random.choice(Perovskite_Structure.C)
    Cii_site = random.choice(Perovskite_Structure.C)

    while covalent_radii[chemical_symbols.index(A_site)] - \
        covalent_radii[chemical_symbols.index(B_site)] < 0.05 or \
        covalent_radii[chemical_symbols.index(A_site)] - \
        covalent_radii[chemical_symbols.index(B_site)] > 0.5:

        A_site = random.choice(Perovskite_Structure.A)
        B_site = random.choice(Perovskite_Structure.B)

    return crystal(
        [A_site, B_site, Ci_site, Cii_site],
        [(0.5, 0.25, 0.0), (0.0, 0.0, 0.0), (0.0, 0.25, 0.0), (0.25, 0.0, 0.75)],
        spacegroup=62, cellpar=[lat*math.sqrt(2), 2*lat, lat*math.sqrt(2), 90, 90, 90]
    )