You can create a list with your value (1 - 20, 1 - 200) and a random number, and then sort the list by random number.
public class RandomListItem
{
int value;
int sortindex;
public RandomListItem(x,y)
{
value = x;
sortindex = y;
}
}
for(int i = 1; i <= maxvalue; i++)
{
list.add(new RandomListItem(i, getrand100());
}
This may not be so good for a list of 200, as you can generate random numbers up to 100. You might want to use getrand100 () * getrand100 () or something to create a wider range of random numbers.
source
share