[CCing bug-gnulib] Hi Corinna,
> Looking into all the BSD variants of random(), I found that OpenBSD > defaults the random() function to return non-deterministic output. It > works like this: > > - A global var random_deterministic defaults to 0. > - Calls to srandom() set random_deterministic to 0 and ignore their > input. > - Calls to srandom_deterministic() sets random_deterministic to 1 and > seeds the usual PRNG. > - initstate() and setstate() set random_deterministic to 1. > - random() returns either the next value from the PRNG if > random_deterministic is 1, or the next value generated by a call to > arc4random() if random_deterministic is 0. So by default, it > returns arc4random() values. > > With that behaviour, OpenBSD appears to stray from POSIX deliberately. Yup, I observed this too when I found that the gnulib MT test for random() yielded strange results on OpenBSD. [1] > I was wondering if you want to add this as incompatibility to your > document at > https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/posix-functions/random.texi > perhaps. I documented it as an incompatibility for the srandom() function. But you are right, it's also an incompatibility for the random() function, since POSIX [2] says "random() shall produce by default a sequence of numbers that can be duplicated by calling srandom() with 1 as the seed". [1] https://lists.gnu.org/archive/html/bug-gnulib/2023-11/msg00079.html [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/random.html 2023-11-14 Bruno Haible <br...@clisp.org> doc: Mention a 'random' limitation on OpenBSD. Reported by Corinna Vinschen <vinsc...@redhat.com>. * doc/posix-functions/random.texi: Mention the OpenBSD limitation. diff --git a/doc/posix-functions/random.texi b/doc/posix-functions/random.texi index 84cacbe8b5..6f003ea3b6 100644 --- a/doc/posix-functions/random.texi +++ b/doc/posix-functions/random.texi @@ -25,4 +25,8 @@ This function has a slightly incompatible declaration (the return type being @samp{int} instead of @samp{long}) on some platforms: Cygwin 1.5.25, Haiku. +@item +When @samp{srandom} was not called, this function returns a non-deterministic +sequence rather than a deterministic sequence of numbers on some platforms: +OpenBSD 7.4. @end itemize