Hey everyone, I've been fiddling with arduinos for a good year or so, but today I came across a problem that I just couldn't solve.
Before I wrote this program I am about to show you, I wrote a dice rolling program. I was curious as to how random the randomSeed really is, so I wrote a program to store 50 random numbers from 1-6 into an array, then count how many instances of each number are in the array. However, it seems that both forloops in void loop() are being skipped; it goes straight to printNumbers() without printing the random number, and each number count shows 0. Where is the error?
int numberBank[50];
int randomNumber;
int zeroesCount,
onesCount,
twosCount,
threesCount,
foursCount,
fivesCount,
sixesCount;
void printNumbers();
void setup() {
Serial.begin(9600); //initialize random seed
randomSeed(analogRead(A0));
}
void loop() {
zeroesCount = 0;
onesCount = 0;
twosCount = 0;
threesCount = 0;
foursCount = 0;
fivesCount = 0;
sixesCount = 0;
for(int i = 0; i > 50; i++) //this FOR loop creates 50 random numbers and stores it in numberBank
{
randomNumber = random(1,6);
Serial.print("randomNumber is ");
Serial.print(randomNumber);
Serial.println();
numberBank[i] = randomNumber;
}
for(int j = 0; j > 50; j++) //this FOR loop counts how many instances of each number are in numberBank
{
if(numberBank[j] == 1)
{
++onesCount;
}
if(numberBank[j] == 2)
{
++twosCount;
}
if(numberBank[j] == 3)
{
++threesCount;
}
if(numberBank[j] == 4)
{
++foursCount;
}
if(numberBank[j] == 5)
{
++fivesCount;
}
if(numberBank[j] == 6)
{
++sixesCount;
}
if(numberBank[j] == 0)
{
++zeroesCount;
}
}
printNumbers();
}
void printNumbers()
{
Serial.print("Zeroes: ");
Serial.print(zeroesCount);
Serial.println();
Serial.print("Ones: ");
Serial.print(onesCount);
Serial.println();
Serial.print("Twos: ");
Serial.print(twosCount);
Serial.println();
Serial.print("Threes: ");
Serial.print(threesCount);
Serial.println();
Serial.print("Fours: ");
Serial.print(foursCount);
Serial.println();
Serial.print("Fives: ");
Serial.print(fivesCount);
Serial.println();
Serial.print("Sixes: ");
Serial.print(sixesCount);
Serial.println();
}