Perhaps it was rude sending off list stuff to the list. Your email sounded
"less than friendly" and more of a professional challenge that you were
definitely in the works to produce; much like Damien Miller’s challenge to
prove correctness. So, whatever.
Aside from that unpleasantness:
I worked in __builtin_clz(upperbound-1) mentioned earlier in the thread;
instead of my binary search. It made the knuth sort simulation run even
faster. arc4random_uniform now takes 130% of the time mine takes for a
series of random numbers decreasing from 65535 to 2.
“__builtin_clz((upperbound - 1) | 1)” is only needed if upperbound can be 1
and that possibility is eliminated by first checking to see that upperbound
is >= 2.
static uint32_t
arc4random_uniform_small_unlocked(uint32_t upper_bound)
{
static uint64_t rand_holder = 0;
static size_t rand_bits = 0;
static size_t upper_bound0 = 2;
static size_t bitmask = 0x01;
static size_t bits = 1;
const size_t ub = upper_bound;
size_t ret;
if (ub != upper_bound0) {
if (ub < 2) {
/*
* reset static cache for if a process needs to
fork()
* to make it manually fork-safe
*/
if (ub == 0) {
rand_holder = 0;
rand_bits = 0;
}
return 0;
}
bits = 32 - __builtin_clz(ub - 1);
bitmask = ((size_t)1 << bits) - 1;
upper_bound0 = ub;
}
do {
if (rand_bits < bits) {
rand_holder |= ((uint64_t)arc4random()) <<
rand_bits;
/*
* rand_bits will be between 0 and 31 here
* so the 0x20 bit will be empty
* rand_bits += 32;
*/
rand_bits |= 32;
}
ret = rand_holder & bitmask;
rand_holder >>= bits;
rand_bits -= bits;
} while (ret >= ub);
return (uint32_t)ret;
}
> Luke,
>
> It's very bad etiquette to deliberately re-post a private, off-list comment
> to a public mailing list.
>
Also, please fix your email client to respect the Mail-Followup-To: header,
> this is another lack of etiquette on your part.
>
I am either using gmail app on a phone or gmail.com, so I don't know if I
can help you there.