def best_APD_gain(I, Rload, Idark, x, T):
    """
    Return best gain for an avalanche photodiode.

    Args:
        I     = current         (A)
        Idark = dark current    (A)
        Rload = load resistance (Ohms)
        x     = excess noise (0.3 for Si, 0.7 for InGaAs, 1.0 for Ge APDs)
        T     = Temperature
    Returns:
        optimal gain (--)
    """
    q = 1.602e-19  # Coulomb
    k = 1.38e-23   # J/K
    return (4 * k * T / (x * q * Rload * (I + Idark)))**(1 / (x + 2))