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.