]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
libmisc/csrand.c: Update comments
authorAlejandro Colomar <alx.manpages@gmail.com>
Sat, 3 Jun 2023 17:25:00 +0000 (19:25 +0200)
committerSerge Hallyn <serge@hallyn.com>
Mon, 5 Jun 2023 21:50:40 +0000 (16:50 -0500)
Those comments were written when this function used 64 bits (and
temporary variables of 128 bits).  Now it uses 32 bits, with temporaries
of 64 bits, so some values have changed.

Fixes: 2a61122b5e8f ("Unoptimize the higher part of the domain of csrand_uniform()")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
libmisc/csrand.c

index 2557fac8b3546e04bb37a98f7db600c72bca0b3b..e85eaa8a4b44e83b40e22d1fd3bbbe4f6847f0af 100644 (file)
@@ -110,15 +110,15 @@ csrand_uniform32(uint32_t n)
        if (n == 0)
                return csrand();
 
-       bound = -n % n;  // analogous to `2^64 % n`, since `x % y == (x-y) % y`
+       bound = -n % n;  // analogous to `2^32 % n`, since `x % y == (x-y) % y`
 
        do {
                r = csrand();
                mult = r * n;
-               rem = mult;  // analogous to `mult % 2^64`
-       } while (rem < bound);  // p = (2^64 % n) / 2^64;  W.C.: n=2^63+1, p=0.5
+               rem = mult;  // analogous to `mult % 2^32`
+       } while (rem < bound);  // p = (2^32 % n) / 2^32;  W.C.: n=2^31+1, p=0.5
 
-       r = mult >> WIDTHOF(n);  // analogous to `mult / 2^64`
+       r = mult >> WIDTHOF(n);  // analogous to `mult / 2^32`
 
        return r;
 }