mardi 10 avril 2018

How to randomly insert String numbers into an array-Java

I have this array here that takes strings values this is my Puzzle Board View, Right now everything works but the array is hard coded and i need the strings to be generated randomly from 0-4. I have tried to get a random char and put it is as a string but this didnt work any tips would be nice.

Random rand = new Random();
      char c = (char)(rand.nextInt(5) + '0');
      StringBuilder sb = new StringBuilder();
      sb.append(c);

String[] debug_board_state  = new String[7];
    debug_board_state[0] = "0,3,0,0,3,0,2";
    debug_board_state[1] = "1,0,2,0,0,1,2";
    debug_board_state[2] = "0,2,0,0,0,0,0";
    debug_board_state[3] = "0,0,3,0,3,0,4";
    debug_board_state[4] = "2,0,0,0,0,1,0";
    debug_board_state[5] = "0,1,0,0,1,0,2";
    debug_board_state[6] = "2,0,3,0,0,2,0"; 




Aucun commentaire:

Enregistrer un commentaire