-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandInt.java
More file actions
executable file
·27 lines (26 loc) · 839 Bytes
/
RandInt.java
File metadata and controls
executable file
·27 lines (26 loc) · 839 Bytes
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
import java.util.Random;
public class RandInt {
private static final Random rand = new Random();
/**
* @param min Minimum Value (Included)
* @param max Maximum Value (Included)
* @return Random number between min and max
*/
public static int tra(int min, int max) {
return (int) Math.round(rand.nextDouble() * (max - min) + min);
}
/**
* @param max Maximum Value (Included)
* @return Random number between 0 and max
*/
public static int fromZero(int max) {
return (int) Math.round(rand.nextDouble() * max);
}
/**
* @param max Maximum Value (Included)
* @return Random number between 1 and max
*/
public static int fromOne(int max) {
return (int) Math.round(rand.nextDouble() * (max - 1) + 1);
}
}