Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: mergesort code segfaulting on smallish arrays Date: Fri, 08 Nov 2019 19:55:56 -0800 Organization: A noiseless patient Spider Lines: 16 Message-ID: <86o8xlem9f.fsf@linuxsc.com> References: <87mud63p3b.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="bd07fdb0e7610947dc98257bdadc7724"; logging-data="13742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+I30SCQKBMTUT1yDflrxumHbhsvR6LxUI=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:yi4JJ4/vDBXB2nISf+lsrbCkXPY= sha1:Zd/LzfDn/p6FD/Bkr8KbvvZn9jk= Xref: csiph.com comp.lang.c:147807 Ben Bacarisse writes: > Bonita Montero writes: > >> int randIt( int low, int high ) >> { >> return low + (int)((uint64_t)rand() * (unsigned)(high - low) / RAND_MAX); >> } > > This function has numerous problems. [...] perhaps the most > dangerous is that it can return high. [...] Isn't it the case that the routine being discussed is supposed to be able to return the value high? More specifically, that the interval of possible values is meant to include both endpoints? I thought it was.