I am making an Array that is 10 integers long, so that each place 0-9 contains a different integer 0-9.
I am having trouble figuring out how to check if the array already contains a certain number, and if so, regenerating a new one.
So far I have:
for (int i = 0; i < perm.length; i++)
{
int num = (int) (Math.random() * 9);
int []
perm[i] = num;
}
from How can I test if an array contains a certain value?
this is not enough to loop like this, if collision happens some slots would have been not initalized.
Overall, for this task you better initialize array with values in order and then shuffle it by using random permutation indexes