-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRandomIntegerMaker.java
More file actions
45 lines (34 loc) · 1.3 KB
/
RandomIntegerMaker.java
File metadata and controls
45 lines (34 loc) · 1.3 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
package util;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static dto.GameStartOption.DELIMETER;
public class RandomIntegerMaker {
private RandomIntegerMaker() {
}
public static final int MIN_HEIGHT_INDEX = 0;
public static List<Integer> createRandomIntegers(Integer heights) {
List<Integer> randoms = IntStream.range(MIN_HEIGHT_INDEX, heights)
.mapToObj(Integer::new)
.collect(Collectors.toList());
Collections.shuffle(randoms);
return randoms.stream()
.limit(randInt(heights))
.collect(Collectors.toList());
}
public static List<Integer> createRandomIntegersWithRestriction(Integer heights, List<Integer> restrictions) {
List<Integer> randoms = createRandomIntegers(heights);
return randoms.stream()
.filter(i -> !restrictions.contains(i))
.collect(Collectors.toList());
}
public static List<String> separateUserName(String participants) {
String[] users = participants.split(DELIMETER);
return Arrays.asList(users);
}
public static Integer randInt(int bound) {
return (int) (Math.random() * bound + 1);
}
}