Sunday, 25 August 2013

Automaticly assigning values to array

Automaticly assigning values to array

kleurGebruikt[x][0]
^is a string with a word in it // x meaning 'any value'
kleurGebruikt[x][1]
^is standard "0"
afbeeldingen[][]
^is a new array that will store 2 of each string in kleurGebruikt[x][0]
Basicly what I'm trying to accomplish is that the same string from [x][0]
is never stored more than 2 times in the new array
What I got so far is that it will check the counter and if it is 0 it will
copy the string over and then change the 0 to 1. if it gets the same
string later it will see that it is already used once and copy it once
more. Now my problem is that when it is copied twice, I'm unsure of how to
make it skip this string and try a different one. Any help is appreciated
public void randomAfbeelding() {
Random r = new Random();
int rndm = 0;
for(int i=0; i<4; i++){
for(int j=0; j<5; j++){
rndm = r.nextInt(kleurGebruikt.length);
if (kleurGebruikt[rndm][1] == "0"){
afbeeldingen[i][j] = kleurGebruikt[rndm][0];
kleurGebruikt[rndm][1] = "1";
}
else if (kleurGebruikt[rndm][1] == "1"){
afbeeldingen[i][j] = kleurGebruikt[rndm][0];
kleurGebruikt[rndm][1] = "2";
}
else if (kleurGebruikt[rndm][1] == "2"){
// at this point I need to go back to the start of the
current
// if loop and make it so that a new random string is
searched for
// without leaving a blank space in the array.
}
}
Btw I'm sorry if the title isn't really good. I wasn't really sure how to
explain myself in just a few words
As requested:
Example:
kleurGebruikt[0][0] = "Word 1";
kleurGebruikt[0][1] = "0";
kleurGebruikt[1][0] = "Word 2";
kleurGebruikt[1][1] = "0";
now for example: String afbeeldingen[][] = new String[2][2] What I want is
that afbeeldingen[][] contains "Word 1" 2 times and "Word 2" also 2 times.
what I don't want is random amount of times of "Word 1" and random amount
of times "Word 2"
Thanks

No comments:

Post a Comment