I'm supposed to shuffle a List using a random number, which said random number has to be created through a seed.
The thing is I even tried using a Random number, instead of the one I am creating trough the seed, but it still doesn't work. It didn't shuffle the list.
I've created inside the class Shop:
public class Shop {
private Random rand = new Random();
Which I later inicialize inside the constructor.
Random random = new Random(Conf.SEED_RAND);
this.rand = random;
With the random seed, the seed comes from the Conf class. And is initialized like this.
public static final long SEED_RAND = 31;
But the problem is not originated here. Inside the Shop class I've created a method that is supposed to give out the shirts to vendors, howeverm before I come to that the Collections.shuffle does not work, if the values are of 1,2,3,4,5 then the result after the shuffle will be the same.
public void giveout(){
ArrayList<Shirts> list1 = new ArrayList<>();
for(int i = 0;i<Conf.NUM_SHIRTS;i++){
list1.add(tshirts.get(i));
}
Collections.shuffle(list1, this.rand);
Where I must use a Collections.shuffle(List, Random).
I've never worked with shuffle nor random numbers before, what am I doing wrong?
Thanks :)
Aucun commentaire:
Enregistrer un commentaire