changeset 31936:9d5ccdbae3ad

randi.m: Replace mathematically suspect (flintmax + 1) expressions with flintmax. * randi.m: Replace (flintmax + 1) with flintmax as there is no difference in representation between the two.
author Rik <rik@octave.org>
date Sun, 26 Mar 2023 14:51:44 -0700
parents 3e01ed656bc5
children 162669cd13c8
files scripts/general/randi.m
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/randi.m	Sat Mar 25 17:37:15 2023 -0700
+++ b/scripts/general/randi.m	Sun Mar 26 14:51:44 2023 -0700
@@ -111,13 +111,13 @@
   ## Rejection Algorithm to guarantee unbiased results.  See bug #54619.
   rng = (imax - imin) + 1;              # requested range
   N = prod ([varargin{:}]);             # number of requested elements
-  K = floor ((flintmax () + 1) / rng);  # number of primary integers ...
+  K = floor (flintmax () / rng);        # number of primary integers ...
                                         # mapped to single output
-  p = (K*rng) / (flintmax () + 1);      # expected proportion of used primaries
+  p = (K*rng) / flintmax ();            # expected proportion of used primaries
 
   do
     M = ceil (N/p + 10*sqrt (N/p - N)); # number of requested primary integers
-    r_prim = floor (rand (M,1) * (flintmax () + 1));
+    r_prim = floor (rand (M,1) * flintmax ());
     r_prim = r_prim(r_prim < K*rng);
   until (numel (r_prim) >= N)           # should practically always be true