The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] early unix rand
@ 2024-03-12 12:55 Russ Cox
  2024-03-12 18:08 ` [TUHS] " Russ Cox
  2024-03-12 23:05 ` Jonathan Gray
  0 siblings, 2 replies; 12+ messages in thread
From: Russ Cox @ 2024-03-12 12:55 UTC (permalink / raw)
  To: Ken Thompson, Douglas McIlroy, Rob 'Commander' Pike; +Cc: tuhs

[-- Attachment #1: Type: text/plain, Size: 1622 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2436 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [TUHS] early unix rand
@ 2024-03-12 14:37 Douglas McIlroy
  2024-03-12 16:23 ` [TUHS] " Paul Winalski
  2024-03-12 16:32 ` Ken Thompson
  0 siblings, 2 replies; 12+ messages in thread
From: Douglas McIlroy @ 2024-03-12 14:37 UTC (permalink / raw)
  To: TUHS main list

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

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

It sounds like Ken to me. Although everybody had his
own favorite congruential random number generator,
some worse than others, I believe it was Ken who put
one in the math library.

The very fact that rand existed, regardless of its quality,
enabled a lovely exploit. When Ken pioneered password
cracking by trying every word in word lists at hand, one
of the password files he found plenty of hits in came from
Berkeley. He told them and they responded by assigning
random passwords to everybody. That was a memorable
error. Guessing that the passwords were generated by
a simple encoding of the output of rand, Ken promptly
broke 100% of the newly "hardened" password file.

Doug

[-- Attachment #2: Type: text/html, Size: 1124 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-03-14 19:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12 12:55 [TUHS] early unix rand Russ Cox
2024-03-12 18:08 ` [TUHS] " Russ Cox
2024-03-12 23:05 ` Jonathan Gray
2024-03-13  1:09   ` ron minnich
2024-03-13 16:41     ` ron minnich
2024-03-13 17:17       ` ron minnich
2024-03-13 20:25         ` Rob Pike
2024-03-13 20:34           ` Clem Cole
2024-03-14 19:24             ` Dave Horsfall
2024-03-12 14:37 [TUHS] " Douglas McIlroy
2024-03-12 16:23 ` [TUHS] " Paul Winalski
2024-03-13  1:22   ` Russ Cox
2024-03-12 16:32 ` Ken Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).