jeudi 8 octobre 2015

Arduino language shuffle order of an array

I'm working with arduino , but I can't seem to shuffle an array. the proplem is that with arduino I can't use an arraylist so hat makes it very hard for me to shuffle the array.

What I actually want is a list of numbers from 0 to 52 shuffled. so every time I run the program it is shuffled in a different order with the numbers from 0 to 52

Here is my code:

const int MAXNUMMER = 52;
int numbers[52];



int temp = numbers[first];
//int numbers[first] = numbers[second];
//int numbers[second] = temp;




 void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);

     randomizeList();
 }

 void loop() {
 // put your main code here, to run repeatedly:

 }


 void randomizeList()
 {

 randomSeed(analogRead(A0));
 int r = random(53);


for(int i =0; i < MAXNUMMER; i++)
 {
  if(numbers[i] != r)

   {
  numbers[i] = r;

   Serial.println(numbers[i]);
   }

  }


  }




Aucun commentaire:

Enregistrer un commentaire