I need help working out what I am doing wrong here. Could be that I don't understand arrays properly, but I am trying to generate 50 random numbers into an array with the intention of sorting them after. I am stuck trying to make sure this generator works, any help would be appreciated!
int randomNumber[50];
int i;
void setup() {
Serial.begin(9600);
randomSeed(42);
}
void loop() {
while(i =0, i < 50, i++){
randomNumber[i] = random(0,256);
Serial.print("The Random Number is = ");
Serial.println(randomNumber[i]);
delay(1000);
}
}
You could use a while loop if you wish, although I find it nice to have everything controlling the loop on one line, which the for loop provides.
long randomNumber[50];
void setup() {
int i = 0;
Serial.begin(9600);
randomSeed(analogRead(0));
while (i < 50) {
randomNumber[i] = random(0, 256);
Serial.print("The Random Number ");
Serial.print(i + 1);
Serial.print(" is = ");
Serial.println(randomNumber[i]);
i++;
delay(100);
}
}
void loop() {
}