On Thu, 29 Jul 2021 07:11:26 -0600, "Theo de Raadt" wrote:

> I'm not sure about the tradeoff in this approach.
>
> Won't the lack of precision in double eventually lead to non-uniformity?
>
> The way jot is written, I expect higher ranges to have lots of
> non-uniformity unless a substantial rewrite is undertaken, but I am
> worry your approach creates non-uniformity within the 32-bit range.

I don't think it really makes a difference since the result of
"pow10 * (ender - begin)" will be a double regardless of whether
it is stored in a uint32_t or double.

Changing the type of uintx to uint64_t will also fix the problem.
Perhaps that is more palatable?

 - todd

Index: usr.bin/jot/jot.c
===================================================================
RCS file: /cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.49
diff -u -p -u -r1.49 jot.c
--- usr.bin/jot/jot.c   27 Jun 2019 18:03:36 -0000      1.49
+++ usr.bin/jot/jot.c   29 Jul 2021 17:23:01 -0000
@@ -246,7 +246,7 @@ main(int argc, char *argv[])
        } else { /* Random output: use defaults for omitted values. */
                bool            use_unif;
                uint32_t        pow10 = 1;
-               uint32_t        uintx = 0; /* Initialized to make gcc happy. */
+               uint64_t        uintx = 0; /* Initialized to make gcc happy. */
 
                if (prec > 9)   /* pow(10, prec) > UINT32_MAX */
                        errx(1, "requested precision too large");

Reply via email to