-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
70 lines (60 loc) · 1.38 KB
/
Library.java
File metadata and controls
70 lines (60 loc) · 1.38 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Scrabble (APO Project - CMI L1) Library.java - Library of useful functions
*
* @author Fabian Devel, Valentin Perignon
*/
public class Library {
/**
* Get a random integer in [low, up[
*
* @param low Upper bound
* @param up Lower bound
*
* @return A random integer
*/
public static int getRandomInt(int low, int up) {
return low + (int) (Math.random() * (up - low));
}
/**
* Get a random integer in [0, up[
*
* @param up Lower bound
*
* @return A random integer
*/
public static int getRandomInt(int up) {
return getRandomInt(0, up);
}
/**
* Put a String into an array of int
*
* @param tabInt The array of integers
* @param str The String
* @param splitter The splitter (e.g. ",", "", ...)
*/
public static void StringtoArray(int[] tabInt, String str, String splitter) {
// Variable
String[] tabStr = new String[tabInt.length];
// Split the array
tabStr = str.split(splitter);
// String to int
for (int i = 0; i < tabInt.length; i++)
tabInt[i] = Integer.parseInt(tabStr[i]);
}
/**
* Check if the values of an array are in [min, max]
*/
public static boolean checkValuesOfArray(int[] tab, int min, int max) {
// Variables
boolean isOk = true;
int i = 0;
// Treatment
while (i < tab.length && isOk) {
if (tab[i] < min || tab[i] > max)
isOk = false;
else
i++;
}
return isOk;
}
}