Reading a recent junk-thread, I realized the algorithms for rand
and random have changed numerous times since the late 80's.

As such you cannot trust that a seed given 20 years ago, produces the
same sequence today.

I did a rough study of the commits to our versions.  Other operating
systems changed their algorithms at different times.  I think rand and
random algorithm changed about 5 times (combined).  But wait there is
MORE!  These functions mix "long" and "int", and rely upon wraparound,
so 32-bit vs 64-bit behaviour occur.

I'm wondering if the following wording will disuade people from playing
this stupid deterministic game, or arguing that these specific functions
serve such a purpose.  I suppose the two lessons are:
     - if you need determinism, write your own.
     - do not rely upon an external function which will make your seed
       produce a different result approximately every 8 years.

People keep talking about the value of determinism, and in particular for
these specific function names, so I'm hoping to put the argument to rest.

I stopped short by avoiding the phrase "undefined behaviour".

Index: stdlib/rand.3
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/rand.3,v
retrieving revision 1.19
diff -u -p -u -r1.19 rand.3
--- stdlib/rand.3       9 Dec 2014 21:55:39 -0000       1.19
+++ stdlib/rand.3       12 Feb 2021 05:36:52 -0000
@@ -78,6 +78,9 @@ can be substituted for
 then subsequent
 .Fn rand
 calls will return results using the deterministic algorithm.
+The deterministic sequence algorithm changed a number of times since
+original development, is underspecified, and should not be relied up to
+remain consistant between platforms and over time.
 .Pp
 The
 .Fn rand
Index: stdlib/random.3
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/random.3,v
retrieving revision 1.28
diff -u -p -u -r1.28 random.3
--- stdlib/random.3     9 Dec 2014 21:55:39 -0000       1.28
+++ stdlib/random.3     12 Feb 2021 05:36:52 -0000
@@ -96,6 +96,9 @@ a default table of size 31 long integers
 numbers in the range from 0 to (2**31)\-1.
 The period of this random number generator is very large, approximately
 16*((2**31)\-1), but the results are a deterministic sequence from the seed.
+The deterministic sequence algorithm changed a number of times since
+original development, is underspecified, and should not be relied up to
+remain consistant between platforms and over time.
 .Pp
 The
 .Fn initstate

Reply via email to