-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomSeedChanger.java
45 lines (31 loc) · 1.08 KB
/
RandomSeedChanger.java
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
import java.util.Random;
public class RandomSeedChanger {
public static void main(String[] args) {
Integer lowerRange = 0;
Integer higherRange = 1000000000;
int N = 50;
int seedCount = (int)(N*.10); // 20%
long seeds[] = new long[seedCount];
for(int i=0; i<seedCount; i++)
seeds[i] = i;
Random rand = new Random();
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
rand.setSeed(System.currentTimeMillis());
// setting a seed
if(rand.nextBoolean()) {
System.out.print("Setting a Fixed Seed: ");
int seedIndex = rand.nextInt(seedCount);
rand.setSeed(seeds[seedIndex]);
System.out.println(seeds[seedIndex]);
}
ranks[i] = rand.nextInt(higherRange+1);
System.out.println(ranks[i]);
}
Solution s = new Solution();
long startTime = System.currentTimeMillis();
int numberOfSoldiersWithSameSuperior = s.solution(ranks);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest10 : "+(endTime - startTime)+" milliseconds"+" ; result: "+numberOfSoldiersWithSameSuperior);
}
}