-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selection.ino
57 lines (56 loc) · 1.42 KB
/
Selection.ino
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
void blingSelect () {
Serial.println("Start bling selection...");
unsigned long s = micros();
int n = -10;
bool ru = true;
while (ru) {
n = selectRandArray();
Serial.println("return");
if (n > -3) {
ru = false;
Serial.println("false");
}
}
Serial.println("selected random array containing " + String(n) + " programs in " + String(float(micros() - s) / 1000, 3) + " milliseconds");
}
int selectRandArray () {
for (int i = 0; i < PROGS; i++) {
progRuns[i] = 0;
}
int f = 0;
if (oneOfEach) {
int ti = 0;
for (int j = 0; j < PROGS; j++) {
ti += progLimit[j];
}
for (int i = 0; i < ti; i += 0) {
int val = random(PROGS);
bool limitR = (progRuns[val] >= progLimit[val]);
bool lastSame = (blingPrograms[i - 1] == val);
bool both = limitR || lastSame;
both = !both;
if (i == 0) {
both = true;
}
// Serial.println("\n" + String(limitR) + "\n" + String(lastSame) + "\n" + String(both));
if (both) {
progRuns[val] = progRuns[val] + 1;
blingPrograms[i] = val;
i++;
f = 0;
Serial.println(String(i) + ": " + String(val));
} else {
f++;
}
if (f > 9) {
return -9;
}
}
for (int k = 0; k < PROGS; k++) {
Serial.println("L: " + String(progLimit[k]) + " R: " + String(progRuns[k]));
}
return ti;
} else {
return -1;
}
}