I have this really simple code.
Let's say I have a variable X.
Then all I want to do is create a random value R, if R > X then I want X to become R.
But for some reason, my n_of_buttons_pressed
climbs up and then sometimes drops back to lower values. I can not wrap my head around how it could get a lower value then a previous value.
#define N_OF_BUTTONS 60
int n_of_buttons_pressed;
void setup() {
Serial.begin(9600);
Serial.println("start");
}
void loop() {
n_of_buttons_pressed = (int) max(random(0, N_OF_BUTTONS), n_of_buttons_pressed);
Serial.print("n_of_buttons_pressed:");
Serial.print(n_of_buttons_pressed);
Serial.println();
delay(100);
}