-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRand.java
More file actions
55 lines (40 loc) · 1.29 KB
/
Copy pathRand.java
File metadata and controls
55 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ru.cwcode.cwutils.numbers;
import java.util.concurrent.ThreadLocalRandom;
public class Rand {
public static int ofInt(int max) {
return ofInt(0, max);
}
public static int ofInt(int min, int max) {
if (min >= max) return max;
return ThreadLocalRandom.current().nextInt(min, max);
}
public static long ofLong(long max) {
return ofLong(0, max);
}
public static long ofLong(long min, long max) {
if (min >= max) return max;
return ThreadLocalRandom.current().nextLong(min, max);
}
public static float ofFloat(float max) {
return ofFloat(0.0f, max);
}
public static float ofFloat(float min, float max) {
if (min >= max) return max;
return ThreadLocalRandom.current().nextFloat(min, max);
}
public static double ofDouble(double max) {
return ofDouble(0.0, max);
}
public static double ofDouble(double min, double max) {
if (min >= max) return max;
return ThreadLocalRandom.current().nextDouble(min, max);
}
public static boolean bool() {
return ThreadLocalRandom.current().nextBoolean();
}
public static boolean testChance(double chance) {
if (chance >= 1) return true;
if (chance <= 0) return false;
return ThreadLocalRandom.current().nextDouble() < chance;
}
}