On Mon, Jul 21, 2014 at 02:18:10PM +0400, Maria Kustova wrote:
> +def random_from_intervals(intervals):
> +    """Select a random integer number from the list of specified intervals
> +
> +    Each interval is a tuple of lower and upper limits of the interval. The
> +    limits are included. Intervals in a list should not overlap.
> +    """
> +    total = reduce(lambda x, y: x + y[1] - y[0] + 1, intervals, 0)
> +    r = random.randint(0, total-1) + intervals[0][0]
> +    temp = zip(intervals, intervals[1:])
> +    for x in temp:
> +        r = r + (r > x[0][1])*(x[1][0] - x[0][1] - 1)

Please use space around arithmetic operators:
r = r + (r > x[0][1]) * (x[1][0] - x[0][1] - 1)

Attachment: pgpr4_A5J6IUq.pgp
Description: PGP signature

Reply via email to