This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
List colorList = Arrays.asList(colorArray); Collections.shuffle(colorList); colorArray = (Color) colorList.toArray(); return colorArray[i]; } It is called in a drawCards() method, and 'int i' represents the position of the card. I am using it in a MatchGame which is fully functional except for the fact that I cannot get the colors to generate in pairs and therefore am left with a number of "Old Maids" at the end...
why do you shuffle the array, AND choose a random index? isn't one or the other sufficient?
And i'm not exactly sure how you are using this, but each time you call the generateRandoColor, you create a new random array of colors. it that really what you want?
Joined: May 08, 2007
I'm not passing it a random index, the index is a set position. After I shuffle the cards I place them (in order) in positions ranging from 0 to 17.
....However, you are completely right about generating a new random set of colors every time. I guess I'll take my array declaration out of my method and then split my generateRandomColor method into two methods to set the random array and to retrieve from the random array.