can anybody help me in making a method to generate random number without repetition in Android?
The maximum number is: prjcts.size(); it\'s my JSON Array. And t
Have you tried just using Math.random()?
Just do some casting magic and you'll be good to go:
int index = (int)((double)prjcts.size() * Math.random());
Edit:
If you want prevent repetition, you could create a list with all the possible indices.
int max = prjcts.size();
List indices = new ArrayList(max);
for(int c = 0; c < max; ++c)
{
indices.add(c);
}
Then each time you want a random index, just pick a random item from the list, removing it after from the list when you're done
int arrIndex = (int)((double)indices.size() * Math.random());
int randomIndex = indices.get(arrIndex);
indices.remove(arrIndex);
randomIndex is now guaranteed to be a never-before used index of of your JSON list.