Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Multi-channel rand() Date: Wed, 26 Dec 2018 15:32:26 -0800 Organization: None to speak of Lines: 21 Message-ID: References: <6yOUD.36923$Bu5.21082@fx19.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="32ed57ea5d614545634ff390fd99b31b"; logging-data="10873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19k6ERCIXOiTBv5ToqKkf5v" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ae7kPi/VR6tKg67B2nchhcPUUro= sha1:m4LhBC+q7I5MhwHNrng8YUPYhrA= Xref: csiph.com comp.lang.c:139107 Richard Damon writes: [...] > In many implementations, rand() IS based on the sample code from K&R, > which is very old, very simple, and not very good. The fix isn't to add > ad hoc randomizer fixes like you were suggesting, but to use a better > random number generator, and a source of those algorithms was given earlier. [...] Some rand() implementations are even worse than the sample code from K&R. In the NetBSD implementation, the low order bit of the value returned by rand() alternates 0 and 1, the low order 2 bits repeat with a cycle of length 4. etc. The K&R implementation doesn't do that. https://github.com/Keith-S-Thompson/crude_rand_test -- Keith Thompson (The_Other_Keith) kst@mib.org Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"