belliottsmith commented on code in PR #57:
URL: https://github.com/apache/cassandra-accord/pull/57#discussion_r1302231845


##########
accord-core/src/test/java/accord/burn/random/FrequentLargeRange.java:
##########
@@ -18,59 +18,121 @@
 
 package accord.burn.random;
 
-import accord.utils.Invariants;
+import accord.utils.Gen;
+import accord.utils.Gen.LongGen;
+import accord.utils.Gens;
 import accord.utils.RandomSource;
 
-public class FrequentLargeRange implements RandomLong
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+
+public class FrequentLargeRange implements LongGen
 {
-    private final RandomLong small, large;
-    private final double ratio;
-    private final int steps;
-    private final double lower, upper;
-    private int run = -1;
-    private long smallCount = 0, largeCount = 0;
-
-    public FrequentLargeRange(RandomLong small, RandomLong large, double ratio)
+    private final LongGen small, large;
+    private final Gen<Boolean> runs;
+
+    public FrequentLargeRange(LongGen small, LongGen large, double ratio)
     {
-        Invariants.checkArgument(ratio > 0 && ratio <= 1);
         this.small = small;
         this.large = large;
-        this.ratio = ratio;
-        this.steps = (int) (1 / ratio);
-        this.lower = ratio * .8;
-        this.upper = ratio * 1.2;
+        this.runs = Gens.bools().biasedRepeatingRuns(ratio);
     }
 
     @Override
-    public long getLong(RandomSource randomSource)
+    public long nextLong(RandomSource randomSource)
+    {
+        if (runs.next(randomSource)) return large.nextLong(randomSource);
+        else                         return small.nextLong(randomSource);
+    }
+
+    public static Builder builder(RandomSource randomSource)
     {
-        if (run != -1)
+        return new Builder(randomSource);
+    }
+
+    public static class Builder
+    {
+        private final RandomSource random;
+        private Double ratio;
+        private LongGen small, large;
+
+        public Builder(RandomSource random)
+        {
+            this.random = random;
+        }
+
+        public Builder raitio(double ratio)
+        {
+            this.ratio = ratio;
+            return this;
+        }
+
+        public Builder raitio(int min, int max)
         {
-            run--;
-            largeCount++;
-            return large.getLong(randomSource);
+            this.ratio = ratio = random.nextInt(min, max) / 100.0D;

Review Comment:
   redundant assignment?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to