I'm trying to generate an array with random numbers between certain values, that are unique to the other elements in the array, but the last part can't be achieved with my code, ie. sometimes a number is repeated. Can anyone tell me why?
Thanks in advance
public int[] getRandomArray()
{
int potential=0;
int term=(int)(Math.random()*(numberB+1));
int[] randomArray=new int[bSelected];
randomArray[0]=term;
for(int i=1; i< randomArray.length; i++)
{
do
{
potential=(int)(Math.random()*(numberB+1));
}
while(potential == term);
term=potential;
randomArray[i]=term;
}
return randomArray;
}
//where bSelected is an instance variable
Thanks in advance
