I would like to fill a 3x3 2D array with values 1,2,3.
I need each number to appear for a given times.
For example:
1 appear 2 times
2 appear 4 times
3 appear 3 times
What I need is to store this numbers to array in a random position.
For Example:
1,2,2
3,2,2
1,3,3
I already did this in a simple way, using a counter. So I loop through the 2D array and applying random values of 1 and number 2. I'm checking if the value is 1 and add it in the counter and the same with 2. if one of the counter exceeds the number I have set as the maximum appear times then it continues only with the other value.
Aucun commentaire:
Enregistrer un commentaire