I need to code a program for school that picks two random persons of our class but only once. I think the best way to do this is to create a array with the name of everybody of our classmates and then create a random number to pick the persons from that array. My problem is that I don't know how to get a random number that don't repeat.
my code:
String student[] = {classmates};
int x;
int y;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(A1));
x = random(0,15);
y = random(16,28);
Serial.println(student[x]);
Serial.println(student[y]);
}
void loop() {
}
Can anybody tell me how to get every number/person only once ?
Greetings & thank's for the help
Aucun commentaire:
Enregistrer un commentaire