java - How to have unique random number? -
In this way, I am creating a unique number between 1 and 6 and getting the proper picture from the drawable folder.
random rand = new random (); // n = Number of images, which starts at idx 1 rndInt = rand.nextInt (6) + 1; String imgnem = "card" + rrint; Int id = getResources (). GetIdentifier (IIGNName, "Dribal", getPackageName ()); ImgView.setImageResource (ID);
What I want, I have to call this method seven times, and every time this method should return a unique random number. So that none of the previously selected numbers will come again.
The general approach to this kind of problem is to create and manipulate a list of potential values, Then you need to value an item from the list every time. This will ensure that you do not use more than one value but still allows a random sequence.
Comments
Post a Comment