Shuffling a char() array.

edited May 2017 in Questions about Code

Hey, just wondering if anyone could give me a hand with shuffling.

I've got an char array and I would like to shuffle and print the updated array when the mouse is pressed.

Thanks :)

char [] letters;

void setup() {
  size (500, 500);
  creating_letters();
}

void draw () {

  background(200);

  //input size here
  printing_letters(30);
}

void creating_letters () {
  letters = new char [20];

  for (int i = 0; i < letters.length; i++) {
    letters [i] = (char) int(random(33, 100));
  }
}

void printing_letters(int size) {

  int textSize = size;
  for (int i = 0; i<letters.length; i++) {
    textSize(textSize);
    fill(0);
    text((letters[i]), ((i*(textSize/1.3))+10), height/2);
    fill(255);
  }

 if ((mousePressed) && (mouseButton == LEFT)){
   Shuffle();
 }
}


void Shuffle () {

//not sure what to do :/
  letters = sort (letters, int(random(letters.length)));

}
Tagged:

Answers

Sign In or Register to comment.