String a="aaa";
String b="bbb";
String c="ccc";
String d="ddd";
String p,q,r,s;
How can I assign values to p,q,r,s randomly from a,b,c,d?
Like p should have value from a,b,c,d and similarly for q,r,s
But the value should not repeat.
String a="aaa";
String b="bbb";
String c="ccc";
String d="ddd";
String p,q,r,s;
How can I assign values to p,q,r,s randomly from a,b,c,d?
Like p should have value from a,b,c,d and similarly for q,r,s
But the value should not repeat.
The easiest way to do it is probably to just put all the strings in a array (or list, or similar), shuffle the list and assign the first value in the shuffled array to p, the second to q, etc.
Here's an example of how to do this:
String[] strings = new String[] {
"aaa", "bbb", "ccc", "ddd"
};
Collections.shuffle(Arrays.asList(strings));
String p = strings[0],
q = strings[1],
r = strings[2],
s = strings[3];
Add your Strings to a List<String> and then use java.util.Random class's nextInt(sizeOfList) method.