your unnatural use of starting the array indices at 1 makes it hard to see your issue...
here is a refactored, functional approach:
#define NUMBER_OF_STUDENTS 20
const char *players[NUMBER_OF_STUDENTS]={
"Student 0",
"Student 1",
"Student 2",
"Student 3",
"Student 4",
"Student 5",
"Student 6",
"Student 7",
"Student 8",
"Student 9",
"Student 10",
"Student 11",
"Student 12",
"Student 13",
"Student 14",
"Student 15",
"Student 16",
"Student 17",
"Student 18",
"Student 19",
};
int choices[NUMBER_OF_STUDENTS];
int choicesMade;
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(A0));
resetNames();
}
void loop()
{
int studentId = selectRandomNameFromRemaining();
if(studentId == -1)
{
Serial.println(F("hat is empty"));
resetNames();
delay(5000);
}
else
{
Serial.println(players[studentId]);
}
delay(1000);
}
int selectRandomNameFromRemaining()
{
if(choicesMade >= NUMBER_OF_STUDENTS)
{
return -1;
}
int selection = random(choicesMade, NUMBER_OF_STUDENTS);
int temp = choices[choicesMade];
choices[choicesMade] = choices[selection];
choices[selection] = temp;
return choices[choicesMade++]; //moved incrementing choicesMade to here
}
bool resetNames()
{
for (int i = 0; i < NUMBER_OF_STUDENTS; i++)
{
choices[i] = i;
}
for (int i = 0; i < NUMBER_OF_STUDENTS; i++)
{
int index = random(i, NUMBER_OF_STUDENTS);
int temp = choices[i];
choices[i] = choices[index];
choices[index] = temp;
}
choicesMade = 0;
}