Add support for java.util.concurrent.ThreadLocalRandom

This commit is contained in:
Chris Smowton
2021-03-08 10:59:53 +00:00
parent e3cf5c235e
commit 4a4f4b01a1
3 changed files with 41 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
| Test.java:9:5:9:25 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:10:5:10:26 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:13:5:13:35 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:14:5:14:36 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:10:5:10:25 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:11:5:11:26 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:14:5:14:35 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:15:5:15:36 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:20:5:20:27 | abs(...) | Incorrect computation of abs of signed integral random value. |
| Test.java:21:5:21:28 | abs(...) | Incorrect computation of abs of signed integral random value. |

View File

@@ -1,4 +1,5 @@
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.lang3.RandomUtils;
public class Test {
@@ -15,6 +16,14 @@ public class Test {
Math.abs(RandomUtils.nextInt(1, 10)); // GOOD: random value already has a restricted range
Math.abs(RandomUtils.nextLong(1, 10)); // GOOD: random value already has a restricted range
ThreadLocalRandom tlr = ThreadLocalRandom.current();
Math.abs(tlr.nextInt());
Math.abs(tlr.nextLong());
Math.abs(tlr.nextInt(10)); // GOOD: random value already has a restricted range
Math.abs(tlr.nextLong(10)); // GOOD: random value already has a restricted range
Math.abs(tlr.nextInt(1, 10)); // GOOD: random value already has a restricted range
Math.abs(tlr.nextLong(1, 10)); // GOOD: random value already has a restricted range
}
}