mirror of
https://github.com/github/codeql.git
synced 2026-06-13 08:51:20 +02:00
30 lines
1.1 KiB
Java
30 lines
1.1 KiB
Java
import java.util.Random;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
|
public class Test {
|
|
|
|
public static void test() {
|
|
|
|
Random r = new Random();
|
|
Math.abs(r.nextInt()); // $ Alert
|
|
Math.abs(r.nextLong()); // $ Alert
|
|
Math.abs(r.nextInt(100)); // GOOD: random value already has a restricted range
|
|
|
|
Math.abs(RandomUtils.nextInt()); // $ Alert
|
|
Math.abs(RandomUtils.nextLong()); // $ Alert
|
|
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()); // $ Alert
|
|
Math.abs(tlr.nextLong()); // $ Alert
|
|
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
|
|
|
|
}
|
|
|
|
}
|