Hello Guys, good day to all of you.
just started this week learning how to program in arduino and i was practicing how to generate random numbers. Here is the thing guys, the random number will only generate from 0 to 9 and i just want to only generate it 10 times. Let us say the if the number 0 is already generated, and i just want to not to generate it no more throughout the whole process of the program, by the way my output here is the 7-segment. What will i do to generate a non repeating numbers or how do I will generate a non-repeating numbers? will you guys give me a tip or help me how to do it ? thank you in advance. i posted the program that i made. bulbs [] is for the digital pin of the arduino from 3 to 9, num[] is to state the 7-segment are to off.
int bulbs[] = {3, 4, 5, 6, 7, 8, 9};
int num[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int randnumbers;
void setup()
{
for (int x = 0; x < 7; x++)
{
pinMode(bulbs[ x ], OUTPUT);
}
}
void loop()
{
randnumbers = random(0, 10);
for (int x = 0; x < 7; x++)
{
if (randnumbers == 0)
{
ChangeNumber(LOW, HIGH, HIGH, LOW, LOW, LOW, LOW);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 1)
{
ChangeNumber(HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 2)
{
ChangeNumber(HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 3)
{
ChangeNumber(LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 4)
{
ChangeNumber(HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 5)
{
ChangeNumber(HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 6)
{
ChangeNumber(HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 7)
{
ChangeNumber(HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 8 )
{
ChangeNumber(HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH);
digitalWrite(bulbs[ x ], num[ x ] );
}
else if (randnumbers == 9)
{
ChangeNumber(HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW);
digitalWrite(bulbs[ x ], num[ x ] );
}
}
delay(1000);
}
void ChangeNumber( int n0, int n1, int n2, int n3, int n4, int n5, int n6)
{
num[0] = n0;
num[1] = n1;
num[2] = n2;
num[3] = n3;
num[4] = n4;
num[5] = n5;
num[6] = n6;
}