So in my game I want to randomize some player colors. There is a list of 4 colors I set up and I want to assign a player a random color. The problem is I want to assign each player a different color. Thinking about this in general programming terms I want to scramble or randomize an already existing array or at least the indices into an array without duplicates. Does this exist some how?
The only way I figured I could do this myself is to do a loop to get a random number between 0-array length and insert it into another array (if I did not already pull that random number already)… but this seems insufficient.
OK. I don’t think you read my question. If I have 4 colors and want to randomize what color each player has then I can easily run into 2 players grabbing the same color.
Why not remove the color from the array after it has been assigned to a player?
There are a few ways to randomize arrays though if you really want to go that route. You just have a multiple arrays which then randomly trade indexes and output a final scrambled array. Kind of like mixing drinks.