RandomGeneratorRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$).* as compiler argument.

Table of contents
  1. RandomGeneratorNextDouble
  2. RandomGeneratorNextDoubleWithOrigin
  3. RandomGeneratorNextInt
  4. RandomGeneratorNextIntWithOrigin
  5. RandomGeneratorNextLong
  6. RandomGeneratorNextLongWithOrigin

RandomGeneratorNextDouble

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextDouble") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextDouble).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Double> testRandomGeneratorNextDouble() {
   return ImmutableSet.of(
-      new Random().nextDouble() * 1,
-      2L * new SplittableRandom().nextDouble(),
-      new SecureRandom().nextDouble() * 3.0);
+      new Random().nextDouble(1),
+      new SplittableRandom().nextDouble(2L),
+      new SecureRandom().nextDouble(3.0));
 }

RandomGeneratorNextDoubleWithOrigin

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextDoubleWithOrigin") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextDoubleWithOrigin).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 double testRandomGeneratorNextDoubleWithOrigin() {
-  return 1.0 + new Random().nextDouble(2.0);
+  return new Random().nextDouble(1.0, 1.0 + 2.0);
 }

RandomGeneratorNextInt

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextInt") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextInt).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Integer> testRandomGeneratorNextInt() {
-  return ImmutableSet.of(
-      (int) new Random().nextDouble(1), (int) Math.round(new SplittableRandom().nextDouble(2)));
+  return ImmutableSet.of(new Random().nextInt(1), new SplittableRandom().nextInt(2));
 }

RandomGeneratorNextIntWithOrigin

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextIntWithOrigin") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextIntWithOrigin).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 int testRandomGeneratorNextIntWithOrigin() {
-  return 1 + new Random().nextInt(2);
+  return new Random().nextInt(1, 1 + 2);
 }

RandomGeneratorNextLong

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextLong") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextLong).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Long> testRandomGeneratorNextLong() {
   return ImmutableSet.of(
-      (long) new Random().nextDouble((double) 1L),
-      Math.round(new SplittableRandom().nextDouble((double) 2L)),
-      (long) new SecureRandom().nextDouble(3L),
-      Math.round(ThreadLocalRandom.current().nextDouble(4L)));
+      new Random().nextLong(1L),
+      new SplittableRandom().nextLong(2L),
+      new SecureRandom().nextLong(3L),
+      ThreadLocalRandom.current().nextLong(4L));
 }

RandomGeneratorNextLongWithOrigin

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextLongWithOrigin") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextLongWithOrigin).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 long testRandomGeneratorNextLongWithOrigin() {
-  return 1L + new Random().nextLong(2L);
+  return new Random().nextLong(1L, 1L + 2L);
 }

Copyright © 2017-2026 Picnic Technologies BV