[TUHS] early unix rand

Russ Cox rsc at swtch.com
Tue Mar 12 22:55:02 AEST 2024


Hi all (and TUHS),

The Third Edition rand(III) page [1] ends with

WARNING  The author of this routine has been writing
    random-number generators for many years and has
    never been known to write one that worked.

My understanding is that Ken wrote the rand implementation.
But I'm curious about the origin of this warning.
I had assumed that Ken wrote it as a combination warning+joke,
but Rob suggested that to him it didn't sound like Ken and
perhaps Doug or Dennis had written it. Does anyone remember?

Separately, I am trying to find out what the very first
Unix rand implementation was. In the TUHS archives,
the incomplete V2 sources contain a reference to srand
in cmd/bas0.s [2], but there is no definition in the tree.
The V3 man pages list it, but as far as I can tell full
library sources do not appear in the TUHS archives
until the V6 snapshot. The V6 rand [3] is:

rand:
    mov r1,-(sp)
    mov ranx,r1
    mpy $13077.,r1
    add $6925.,r1
    mov r1,r0
    mov r0,ranx
    bic $100000,r0
    mov (sp)+,r1
    rts pc

Perhaps this is the original rand as well? It is hard to imagine
a much simpler one, other than perhaps removing the addition,
but doing so would create a sequence of only odd numbers.
>From the man page description it sounds like this has to be the
original generator, perhaps with different constants.

Thanks!

Best,
Russ

[1]
https://github.com/dspinellis/unix-history-repo/blob/Research-V3/man/man3/rand.3
[2]
https://github.com/dspinellis/unix-history-repo/blob/Research-V2/cmd/bas0.s
[3]
https://github.com/dspinellis/unix-history-repo/blob/Research-V6/usr/source/s3/rand.s
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20240312/08481858/attachment.htm>


More information about the TUHS mailing list