My co-worker was troubleshooting why some of our unittests (that work on multiple operating systems and architectures) failed on OpenBSD and saw that if you call srandom(0) to initialize the RNG, random() will always return 0. (I was able to reproduce this.)
If this is expected behaviour, please point to explanation. He posted his tests and discussed the code related to this at: https://banu.com/blog/42/openbsd-bug-in-the-random-function/ He suggests two ways to fix this: 1) if (x == 0) x = 1; upon entry in srandom(). That's the glibc way and he thinks is the better solution as it falls back to the default behavior (when srandom is not called) when the impossible seed=0 is passed. 2) the second way to fix it is the FreeBSD way: for (i = 1; i < rand_deg; i++) { + if (state[i-1] == 0) + state[i-1] = 123459876; val = div(state[i-1], 127773);
