On Sun, Mar 03, 2024 at 12:58:20AM +0100, Elie Le Vaillant wrote: > I'm using the web interface to the mailing list to check what has been > sent, and these patches were not sent.
The web archive is not reliable and often drops mails. > + * Copied off OpenBSD (original is arc4random_uniform) > + */ > +uint32_t > +random_uniform(uint32_t upper_bound) I'd recommend using the bitmask approach described in here: https://www.pcg-random.org/posts/bounded-rands.html#bitmask-with-rejection-unbiased-apples-method And if you want a portable clz without depending on __builtin_clz() then see: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 > + r = random(); /* arc4random() is better, but we don't always > have it */ I'm not sure why you think arc4random() is better. I doubt you need any cryptograhic guarantees here. Personally I'd just go with a simple PCG construction. It takes about ~6 lines of code [0], is fast and has good statistical properties. Would also avoid spending time locking/unlocking mutex inside libc for no reason. [0]: https://github.com/imneme/pcg-c-basic/blob/bc39cd76ac3d541e618606bcc6e1e5ba5e5e6aa3/pcg_basic.c#L60-L67 or: https://codeberg.org/NRK/slashtmp/src/branch/master/prng/pcg_32.c - NRK