From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 29 08:39:40 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5E091FFC for ; Fri, 29 Aug 2014 08:39:40 +0000 (UTC) Received: from mail-lb0-x22e.google.com (mail-lb0-x22e.google.com [IPv6:2a00:1450:4010:c04::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D779B1964 for ; Fri, 29 Aug 2014 08:39:39 +0000 (UTC) Received: by mail-lb0-f174.google.com with SMTP id p9so2224708lbv.19 for ; Fri, 29 Aug 2014 01:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=qD1volQVAHPW1QoUdoSmD3K+bRpXXs+XEqAvUZRVDTQ=; b=jG5YeB0aRY4RjhXw+E6qqwqE5k55DH/Lw4luf2KGww2aJx+IxuT76myQ7XvY1aFug1 4EVwYk3pNGQf3/Bd8zsXS3qVKIrF2yu0+XsUGpN4uMAYARyItP8TLHGvGZQVYI0HraIS l52LJqVVqkvRZp1WExVIZ9NBG96Sva4Ug9BF581VPCwrtBRWfqhON4SmINwLaWadmS6F CDXxZj69WZbmt1j17uLaO0d9LzXxmsZ+NWSvzeeDFxopstR4/QyjqvqkxKdODD+nZEHk ZXuet1PbNa1nmqXLA93A0Ch6HaKQsh4KKi/iGELAcgqNUN4U1z4hoJf5dCnHGxvkwgc9 7aFg== X-Received: by 10.152.4.9 with SMTP id g9mr10070847lag.14.1409301577768; Fri, 29 Aug 2014 01:39:37 -0700 (PDT) Received: from [172.29.2.131] (altimet-gw.cs2.dp.wnet.ua. [217.20.178.249]) by mx.google.com with ESMTPSA id f6sm4091770lae.7.2014.08.29.01.39.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Aug 2014 01:39:37 -0700 (PDT) Message-ID: <54003C42.1070309@gmail.com> Date: Fri, 29 Aug 2014 11:39:30 +0300 From: Vitaly Magerya User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Chenguang Li Subject: Re: On changing rand(3) to random(3) in awk(1) References: <53FEFBB8.5040305@gmail.com> <20140828131526.GA2385@straylight.m.ringlet.net> <5C40F611-22EB-49E4-8925-37922E771C0F@gmail.com> <53FF574E.1090108@gmail.com> <78248D53-D8B6-4135-B900-74E0047F92F1@gmail.com> In-Reply-To: <78248D53-D8B6-4135-B900-74E0047F92F1@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Aug 2014 08:39:40 -0000 On 2014-08-29 10:12, Chenguang Li wrote: >> OK, so this part is wrong (and it is wrong in the original sources >> too): this construction generates 0.0 twice as often as it generates >> other numbers -- both when random() returns 0 and when it returns >> RANDOM_MAX. The correct construction is this: > > Yes, I've noticed there's a fairness problem, 0 comes out more often. Since > the original code is buggy too, do we need to be compatible with it? I see no reason why we would. Interestingly enough, GNU awk has this bug as well (and I am entirely too lazy to report it). > Thanks for pointing that out, I've modified the gist as your suggestion. Looks good to me. You might want to open a bug report with that patch, as it's not clear if any committer is reading this thread.