changeset 9396:d0a4dfe19b1d

Doh, third try at this!
author psandoz
date Wed, 14 Aug 2013 14:14:30 +0200
parents 254795c26e39
children d33951658751
files src/share/classes/java/util/Random.java
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Random.java	Wed Aug 14 13:17:43 2013 +0200
+++ b/src/share/classes/java/util/Random.java	Wed Aug 14 14:14:30 2013 +0200
@@ -277,8 +277,10 @@
             if ((n & m) == 0)
                 r = (int)((n * (long)r) >> 31) + origin;
             else if (n > 0) {
-                while (r - (r % n) + m < 0)
-                    r = next(31);
+                for (int u = r;
+                     u - (r = u % bound) + m < 0;
+                     u = next(31))
+                    ;
                 r += origin;
             }
             else {
@@ -393,10 +395,12 @@
         int r = next(31);
         int m = bound - 1;
         if ((bound & m) == 0)  // i.e., bound is a power of 2
-            return (int)((bound * (long)r) >> 31);
+            r = (int)((bound * (long)r) >> 31);
         else {
-            while (r - (r % bound) + m < 0)
-                r = next(31);
+            for (int u = r;
+                 u - (r = u % bound) + m < 0;
+                 u = next(31))
+                ;
         }
         return r;
     }