Message ID | 20200609160620.GA29668@Johns-MacBook-Pro.local |
---|---|
State | Committed |
Delegated to: | Carlos O'Donell |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCFF4388B027; Tue, 9 Jun 2020 16:08:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from plockton.cent.gla.ac.uk (plockton.cent.gla.ac.uk [130.209.16.75]) by sourceware.org (Postfix) with ESMTP id D4849388B026 for <libc-alpha@sourceware.org>; Tue, 9 Jun 2020 16:08:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D4849388B026 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=glasgow.ac.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=John.W.Marshall@glasgow.ac.uk Received: from tmpvpnr181-22.cent.gla.ac.uk ([172.20.181.22] helo=Johns-MacBook-Pro.local) by plockton.cent.gla.ac.uk with smtp (Exim 4.72) (envelope-from <John.W.Marshall@glasgow.ac.uk>) id 1jignu-0000Na-7q for libc-alpha@sourceware.org; Tue, 09 Jun 2020 17:08:46 +0100 Date: Tue, 9 Jun 2020 17:08:45 +0100 From: John Marshall <John.W.Marshall@glasgow.ac.uk> To: libc-alpha@sourceware.org Subject: [PATCH] random: range is not portably RAND_MAX [BZ #7003] Message-ID: <20200609160620.GA29668@Johns-MacBook-Pro.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <http://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <http://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
random: range is not portably RAND_MAX [BZ #7003]
|
|
Commit Message
John Marshall
June 9, 2020, 4:08 p.m. UTC
On other platforms, RAND_MAX (which is the range of rand(3)) may differ from 2^31-1 (which is the range of random(3)). --- The fix applied for BZ #7003 made a similar change to manual/math.texi but this comment was neglected. I am not FSF copyright assigned, but I imagine this change is trivial enough not to need it. Cheers, John stdlib/stdlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On other platforms, RAND_MAX (which is the range of rand(3)) may differ from 2^31-1 (which is the range of random(3)). --- On Tue, Jun 09, 2020 at 05:08:45PM +0100, John Marshall wrote: > The fix applied for BZ #7003 made a similar change to manual/math.texi > but this comment was neglected. I am not FSF copyright assigned, but I > imagine this change is trivial enough not to need it. First ping as per [1] for this triviality. I used interval notation similar to lrand48() etc, but happy to leave it as "between 0 and 2^31-1 inclusive" if that's preferable. Cheers, John [1] https://sourceware.org/glibc/wiki/Contribution%20checklist stdlib/stdlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index f971df4247..fb06bb9ac1 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -397,7 +397,7 @@ extern long int a64l (const char *__s) `initstate' and `setstate' functions are those from BSD Unices. The `rand' and `srand' functions are required by the ANSI standard. We provide both interfaces to the same random number generator. */ -/* Return a random long integer between 0 and RAND_MAX inclusive. */ +/* Return a random long integer in [0,2^31). */ extern long int random (void) __THROW; /* Seed the random number generator with the given number. */
On other platforms, RAND_MAX (which is the range of rand(3)) may differ from 2^31-1 (which is the range of random(3)). --- Second ping as per [1] for this trivial comment fix that completes the fix for BZ #7003 [2] made in 2013. This version of the patch keeps the "between ... inclusive" wording; see the previous version if avoiding writing "2^31-1" is preferred. I am not FSF copyright assigned, but I believe this change is trivial enough not to need it. [1] https://sourceware.org/glibc/wiki/Contribution%20checklist [2] https://sourceware.org/bugzilla/show_bug.cgi?id=7003 stdlib/stdlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index f971df4247..3aa27a9d25 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -397,7 +397,7 @@ extern long int a64l (const char *__s) `initstate' and `setstate' functions are those from BSD Unices. The `rand' and `srand' functions are required by the ANSI standard. We provide both interfaces to the same random number generator. */ -/* Return a random long integer between 0 and RAND_MAX inclusive. */ +/* Return a random long integer between 0 and 2^31-1 inclusive. */ extern long int random (void) __THROW; /* Seed the random number generator with the given number. */
On 6/26/20 8:29 AM, John Marshall wrote: > On other platforms, RAND_MAX (which is the range of rand(3)) > may differ from 2^31-1 (which is the range of random(3)). Agreed. This is the same change for bug 7003, but in the header. I've pushed your change. Thanks! Reviewed-by: Carlos O'Donell <carlos@redhat.com> > --- > Second ping as per [1] for this trivial comment fix that completes > the fix for BZ #7003 [2] made in 2013. This version of the patch > keeps the "between ... inclusive" wording; see the previous version > if avoiding writing "2^31-1" is preferred. > > I am not FSF copyright assigned, but I believe this change is trivial > enough not to need it. > > [1] https://sourceware.org/glibc/wiki/Contribution%20checklist > [2] https://sourceware.org/bugzilla/show_bug.cgi?id=7003 > > stdlib/stdlib.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h > index f971df4247..3aa27a9d25 100644 > --- a/stdlib/stdlib.h > +++ b/stdlib/stdlib.h > @@ -397,7 +397,7 @@ extern long int a64l (const char *__s) > `initstate' and `setstate' functions are those from BSD Unices. > The `rand' and `srand' functions are required by the ANSI standard. > We provide both interfaces to the same random number generator. */ > -/* Return a random long integer between 0 and RAND_MAX inclusive. */ > +/* Return a random long integer between 0 and 2^31-1 inclusive. */ > extern long int random (void) __THROW; > > /* Seed the random number generator with the given number. */ >
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index f971df4247..fb06bb9ac1 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -397,7 +397,7 @@ extern long int a64l (const char *__s) `initstate' and `setstate' functions are those from BSD Unices. The `rand' and `srand' functions are required by the ANSI standard. We provide both interfaces to the same random number generator. */ -/* Return a random long integer between 0 and RAND_MAX inclusive. */ +/* Return a random long integer in [0,2^31). */ extern long int random (void) __THROW; /* Seed the random number generator with the given number. */