mardi 27 octobre 2015

Pick randomly user from list to another list

i'm trying to pick randomly users from this list:

    private static List<User> users = new ArrayList<>();

into this one:

    private static List<Lunchpairs> pairs = new ArrayList<>();

and that's my code:

public static List<Lunchpairs> getPairs() throws NoUserException{

    if(users.isEmpty()){
        throw new NoUserException("No participants.");
    }

    for(int i=0; i< 2; i++){

        Random pickPairs = new Random();
        Lunchpairs randomPairs = users.get(pickPairs.nextInt(users.size()));
        pairs.add(randomPairs);

    }
    return pairs;

}

But it doesn't work like this. I think the problem is that i can't get the names from List<User> and get it into List<Lunchpairs>.(If i'm not right, please let me know)

How can i solve this problem?




Aucun commentaire:

Enregistrer un commentaire