HI..
I HAVE A QUERY ABOUT ARRAY GENERATION:
I have an array named randomval which stores 30 random generated values.
I have an array seat[j] which has 6 numbers stored in it.
I want to print a random number for every j . For the same j ,random numbers should not repeat.
i.e if j=201, i=0 to 30 should print in it.
if j=202 , i-0 to 30 should print in it.
but j wont go in sequence ,
it will be randomly generated i.e after j=201, it might be j=206 or j=207
can someone please give a solution to this.
the basic code I have is as follows:
int randomVals[30];
void setup() {
-
int temp;*
-
int passCounter = 0;*
-
//int elementsFilled = 0;*
-
//randomSeed(analogRead(0)); // Seed generator...*
-
Serial.begin(9600);*
-
while (true) {*
-
temp = random(0, 30);*
-
if (randomVals[temp] == 0) { // If this number has not been generated yet...*
-
randomVals[temp] = passCounter++; // ...write its value here.*
-
//Serial.println(passCounter);*
-
}*
-
if (passCounter > 30) { // If we've filled in all elements, leave...*
-
break;*
-
}*
-
}*
}
void loop()
{
- for (int i = 0; i < 30; i++)*
_ Serial.println(randomVals*)[/color];_
_}*_