const auto usage= R"QQ(Shuffle and deal randomizes an array, deals it out one element as a time, then reshuffles. Repeately pressing the button will show the sequences. Since the randomness is more constrained as the sequence drains, you can guess the last numbers better)QQ";
int questionNumberArray[] = {0, 1, 2, 3, 4, };//5, 6, 7, 8, 9};
const int questionCount = sizeof questionNumberArray / sizeof questionNumberArray[0];
const int button = A0;
int last_button;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(usage);
pinMode(button, INPUT_PULLUP);
// initialise user-based entropy:
last_button = digitalRead(button);
Serial.print("press button when ready...");
while(digitalRead(button) == last_button){delay(10);}
while(digitalRead(button) == !last_button){delay(10);}
randomSeed(random()+micros());
shuffle();
Serial.println("Go!");
}
void loop() {
// put your main code here, to run repeatedly:
static int count = 0;
static int last_button = digitalRead(button);
int nowButton = digitalRead(button);
if (nowButton != last_button) {
last_button=nowButton;
if (nowButton == 0) {
Serial.print(questionNumberArray[count]);
Serial.print(" ");
++count;
if (count >= questionCount) {
count = 0;
shuffle();
Serial.println();
// delay(1);
}
}
delay(5);
}
}
void shuffle() {
// incorporate more user-based entropy
randomSeed(random()+micros());
for (int i = 0; i < questionCount; i++) {
int n = random(0, questionCount); // Integer from 0 to questionCount-1
int temp = questionNumberArray[n];
questionNumberArray[n] = questionNumberArray[i];
questionNumberArray[i] = temp;
}
}