From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5oW-0002yZ-Pa for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:55:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XD5oN-0008Jb-Jm for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:55:36 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:46389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5oN-0008JG-9d for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:55:27 -0400 Received: by mail-we0-f180.google.com with SMTP id w61so3734077wes.11 for ; Thu, 31 Jul 2014 22:55:26 -0700 (PDT) Date: Fri, 1 Aug 2014 06:55:18 +0100 From: Stefan Hajnoczi Message-ID: <20140801055518.GC6875@stefanha-thinkpad.lan> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="96YOpH+ONegL0A3E" Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH V4 3/5] fuzz: Fuzzing functions for qcow2 images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Maria Kustova Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, Maria Kustova --96YOpH+ONegL0A3E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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) --96YOpH+ONegL0A3E Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJT2yvGAAoJEJykq7OBq3PI9I0IAJO1uLQxXmDuUj5REMXxsiNg cJYFJii2zLK0dgdcOnMTu2Detydz5jgjzfEtBwzeRzF+nstwZ8XnCoXGVC4PKAW9 Dj8+Qsam3BggVFXt/+1Xw3gF0o1OHK7T04GpWzxPsE6iMqskKgbgKo7bBHGqIao/ 3FjvkbmklNanDLETqcCe5bv1ARbZCCCJSJNzd2MEyzLv7izw23My2LIcS7EOeoR2 aWBzxe7tvs+9wBQ/0neQKK3U6YQn0PXbPPiym0wvQkf4LnkdsJtLBLMH4XYIvVX1 vKTdItkwrmtPXucpOxXoM3YzVwlxyrE5c6uf1rnO8dqvAbM3MBFAidO7rH4sg2g= =R3OM -----END PGP SIGNATURE----- --96YOpH+ONegL0A3E--