<div dir="auto">There used to be an urban legend about multiply overflow and the PDP 11.</div><div dir="auto"><br></div><div dir="auto">This would’ve been circa 1976. Someone from DEC told us that on a multiply overflow, the contents of the destination register would be “kind of” random. I was never able to verify that claim. But that might explain this code. </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2024 at 16:05 Jonathan Gray <<a href="mailto:jsg@jsg.id.au">jsg@jsg.id.au</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Mar 12, 2024 at 08:55:02AM -0400, Russ Cox wrote:<br>
> Hi all (and TUHS),<br>
> <br>
> The Third Edition rand(III) page [1] ends with<br>
> <br>
> WARNING  The author of this routine has been writing<br>
>     random-number generators for many years and has<br>
>     never been known to write one that worked.<br>
> <br>
> My understanding is that Ken wrote the rand implementation.<br>
> But I'm curious about the origin of this warning.<br>
> I had assumed that Ken wrote it as a combination warning+joke,<br>
> but Rob suggested that to him it didn't sound like Ken and<br>
> perhaps Doug or Dennis had written it. Does anyone remember?<br>
> <br>
> Separately, I am trying to find out what the very first<br>
> Unix rand implementation was. In the TUHS archives,<br>
> the incomplete V2 sources contain a reference to srand<br>
> in cmd/bas0.s [2], but there is no definition in the tree.<br>
> The V3 man pages list it, but as far as I can tell full<br>
> library sources do not appear in the TUHS archives<br>
> until the V6 snapshot. The V6 rand [3] is:<br>
> <br>
> rand:<br>
>     mov r1,-(sp)<br>
>     mov ranx,r1<br>
>     mpy $13077.,r1<br>
>     add $6925.,r1<br>
>     mov r1,r0<br>
>     mov r0,ranx<br>
>     bic $100000,r0<br>
>     mov (sp)+,r1<br>
>     rts pc<br>
<br>
matches V5:<br>
<a href="https://www.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s3/rand.sDistributions/Research/Dennis_v5/v5root.tar.gz" rel="noreferrer" target="_blank">https://www.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s3/rand.s<br>
Distributions/Research/Dennis_v5/v5root.tar.gz</a><br>
<br>
> <br>
> Perhaps this is the original rand as well? It is hard to imagine<br>
> a much simpler one, other than perhaps removing the addition,<br>
> but doing so would create a sequence of only odd numbers.<br>
> >From the man page description it sounds like this has to be the<br>
> original generator, perhaps with different constants.<br>
> <br>
> Thanks!<br>
> <br>
> Best,<br>
> Russ<br>
> <br>
> [1]<br>
> <a href="https://github.com/dspinellis/unix-history-repo/blob/Research-V3/man/man3/rand.3" rel="noreferrer" target="_blank">https://github.com/dspinellis/unix-history-repo/blob/Research-V3/man/man3/rand.3</a><br>
> [2]<br>
> <a href="https://github.com/dspinellis/unix-history-repo/blob/Research-V2/cmd/bas0.s" rel="noreferrer" target="_blank">https://github.com/dspinellis/unix-history-repo/blob/Research-V2/cmd/bas0.s</a><br>
> [3]<br>
> <a href="https://github.com/dspinellis/unix-history-repo/blob/Research-V6/usr/source/s3/rand.s" rel="noreferrer" target="_blank">https://github.com/dspinellis/unix-history-repo/blob/Research-V6/usr/source/s3/rand.s</a><br>
</blockquote></div></div>