def walkscan(x0, y0, xn=0.25, xp=0.25, yn=0.25, yp=0.25):
    """Scan pixels in a random walk pattern with given step probabilities. The
    random walk will continue indefinitely unless a skip transformation is used
    with the 'stop' parameter set or a clip transformation is used with the
    'abort' parameter set to True. The probabilities are normalized to sum to 1.

    :param x0: Initial x-coordinate
    :type x0: int
    :param y0: Initial y-coordinate
    :type y0: int
    :param xn: Probability of moving in the negative x direction
    :type xn: float
    :param xp: Probability of moving in the positive x direction
    :type xp: float
    :param yn: Probability of moving in the negative y direction
    :type yn: float
    :param yp: Probability of moving in the positive y direction
    :type yp: float
    """

    # Validate inputs
    if xn < 0: raise ValueError("Negative x probabilty must be non-negative")
    if xp < 0: raise ValueError("Positive x probabilty must be non-negative")
    if yn < 0: raise ValueError("Negative y probabilty must be non-negative")
    if yp < 0: raise ValueError("Positive y probabilty must be non-negative")

    # Compute normalized probability
    total = xp + xn + yp + yn
    xn /= total
    xp /= total
    yn /= total
    yp /= total

    # Compute cumulative probability
    cxn = xn
    cxp = cxn + xp
    cyn = cxp + yn

    # Initialize position
    x, y = x0, y0

    while True:

        yield x, y

        # Take random step
        probability = random.random()
        if probability <= cxn:
            x -= 1
        elif probability <= cxp:
            x += 1
        elif probability <= cyn:
            y -= 1
        else:
            y += 1
def walkscan ( x0 , y0 , xn = 0.25 , xp = 0.25 , yn = 0.25 , yp = 0.25 ) : if xn < 0 : raise ValueError ( "Negative x probabilty must be non-negative" ) if xp < 0 : raise ValueError ( "Positive x probabilty must be non-negative" ) if yn < 0 : raise ValueError ( "Negative y probabilty must be non-negative" ) if yp < 0 : raise ValueError ( "Positive y probabilty must be non-negative" ) total = xp + xn + yp + yn xn /= total xp /= total yn /= total yp /= total cxn = xn cxp = cxn + xp cyn = cxp + yn x , y = x0 , y0 while True : yield x , y probability = random . random ( ) if probability <= cxn : x -= 1 elif probability <= cxp : x += 1 elif probability <= cyn : y -= 1 else : y += 1
Scan pixels in a random walk pattern with given step probabilities. The
    random walk will continue indefinitely unless a skip transformation is used
    with the 'stop' parameter set or a clip transformation is used with the
    'abort' parameter set to True. The probabilities are normalized to sum to 1.

    :param x0: Initial x-coordinate
    :type x0: int
    :param y0: Initial y-coordinate
    :type y0: int
    :param xn: Probability of moving in the negative x direction
    :type xn: float
    :param xp: Probability of moving in the positive x direction
    :type xp: float
    :param yn: Probability of moving in the negative y direction
    :type yn: float
    :param yp: Probability of moving in the positive y direction
    :type yp: float