This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
One approach - shuffle the array (there is a method in the JDK to do this but you could write your own which is probably what your teacher wants you do do) then use the values at index i and i+1 (i even) as a pair.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre wrote:One approach - shuffle the array (there is a method in the JDK to do this but you could write your own which is probably what your teacher wants you do do) then use the values at index i and i+1 (i even) as a pair.
Joined: Jun 06, 2011
Thank you very much for your replies. Regarding the first post, thanks for the suggesting about the shuffle of the array, I am reading about it.
As regards the 2nd post, thank you for the sample code, actually I had already created something along those lines, but the problem is that the same team can be used more than one match, and thus not all teams are being used.
Except that could pair A with F, then again A with G - the random element can be reselected. A similar approach would be to use a List<String>, then remove the random elements instead of only retrieving them.
And welcome to the Ranch!
James, unfortunately, the shuffle method is only available for Lists, not for arrays. Of course you can wrap the array using Arrays.asList and then shuffle that.
And I'm too slow today - M Mangion addressed my first issue, xinghai huang addressed the second...