I have to create a class that will pick partners at random for my class tomorrow, out of the people that are in it.

What I have so far is simple enough...

import java.util.*;
import java.util.Random;
public class GetPartners {

public GetPartners() {

public void getPartner() {
String[] names = { "Lukas", "Michele", "Megan", "Lindsey", "Victoria", "Andrew", "Gino", "Andrew", "Chris", "Steve", "Ryan", "Dan", "John", "Andre", "Pat", "Ruta", "Vince" } ;
Random r = new Random();
x = r.nextInt(18);
y = r.nextInt(18);
System.out.println(names[y]+" "+names[x]);


private int x;
private int y;


And in a tester class, it picks the partners at random and all, but I don't know what to do to make everyone get a partner and every person to be included... Since the tester repeats people.

7 Years
Discussion Span
Last Post by masijade

And your question? One note though, I would use "names.length" rather than "18" in your random number generation. I would also make "r" an instance variable rather than creating a new one with every call to "getPartner".

Edited by masijade: length, not length + 1, of course


my question is how do I not replicate any names when partners are picked?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.