# HG changeset patch # User Rik # Date 1576786770 28800 # Node ID b3a03dbde858493d7560e5983c1bdffd03c90666 # Parent 9405e2be91d00220d34a304bf99382b7e68c2674 Create equally-spaced floating point values for rand ("double"). * randmtzig.cc (randu53): Get random integer from randi53(). Test and exclude value of 0 (left endpoint of range). Divide by 2^53 to normalize in to range (0, 1) with uniform spacing of eps/2. diff -r 9405e2be91d0 -r b3a03dbde858 liboctave/numeric/randmtzig.cc --- a/liboctave/numeric/randmtzig.cc Thu Dec 19 11:57:54 2019 -0800 +++ b/liboctave/numeric/randmtzig.cc Thu Dec 19 12:19:30 2019 -0800 @@ -393,9 +393,15 @@ /* generates a random number on (0,1) with 53-bit resolution */ static double randu53 (void) { - const uint32_t a = randi32 () >> 5; - const uint32_t b = randi32 () >> 6; - return (a*67108864.0+b+0.4) * (1.0/9007199254740992.0); + uint64_t i; + + do + { + i = randi53 (); + } + while (i == 0); + + return i * (1.0 / 9007199254740992.0); } /* Determine mantissa for uniform doubles */