Skip to content
Advertisement

How to fill ant int array randomly with values from another integer array in Java?

I have an integer array with 40 integer values and need to put these randomly on into another integer array.

I have a random number that chooses a random value from the first array, but if that specific integer has already been chosen, it has to pick a new random value, but that last part seems to bug for some reason.

JavaScript

Advertisement

Answer

Unless you need to implement it as an exercise you could use the built in shuffle method, wrapping your array of available pawns in a list:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement