This is probably an easy one, or my head thinks so. I'm stuck and this is rather important to me.
Declaration
String slota[5];
I have this array of five strings, that I want to fill with "A","B","C","D","E" in random order but without a string having the same letter. So that when i read the array I get
each of the five letters but in any order.
I hope I'm making any sense.
That seems pretty simple:
bool charUsed[5];
int i = 0;
while (i < 5) {
int ran = Random(4); // 0-4 inclusive
if (!charUsed[ran]) {
slota[i] = String.Format("%c", ran + 65); // 65 is the ASCII value of 'A'
charUsed[ran] = true;
i++;
}
}
Now, let's break your happiness probably monkey and let you know that ABCDE was just an example. The actual content is:
CB
DB
AC
BC
AA
String slota[5];
String strings[5];
strings[0] = "CB";
strings[1] = "DB";
strings[2] = "AC";
strings[3] = "BC";
strings[4] = "AA";
bool stringUsed[5];
int i = 0;
while (i < 5) {
int ran = Random(4);
if (!stringUsed[ran]) {
slota[i] = strings[ran];
stringUsed[ran] = true;
i++;
}
}
Thanks a lot monkey. I will marry you one day. :D
Now assume a frictionless environment and recode to account for quantum fluctuations.
[/pointless post day]