Randomization of Groups

I'm having a problem finding a way to completely randomize the people being added to these 4 different groups. It works right now but it isn't fully randomized. Any help would be appreciated.

I've only shuffled it which doesn't solve the issue that it isn't completely random.

public class RandomGroup
{
   /**
    * Arraylist of subgroups in an arraylist of groups 
    * Instance variables fr and sc for file reader and scanner
    */
    private ArrayList<String> subgroup;
    private ArrayList<ArrayList<String>> group;
    public FileReader fr;
    public Scanner sc;


    /**
     * @param subgroup
     * @param group
     */
    public RandomGroup()
    {
    this.subgroup = new ArrayList<String>();
    this.group = new ArrayList<ArrayList<String>>();

    }

    /**
     * Creates a method readAndSopFile uses the scanner class to go through 
     * the file
     * @throws IllegalStateException
     * @throws NoSuchElementException
     */
    public void readAndSopFile() throws IllegalStateException, NoSuchElementException
    {
    while (sc.hasNext())
    {
        String s = sc.next();
        System.out.println(s);
    }
    }
    /**
     * Creates the method groupAndSubgroup
     * @throws IllegalStateException
     * @throws NoSuchElementException
     * @throws FileNotFoundException
     * Creates a fileReader and a scanner to read the file "Students"
     */
    public void groupAndSubgroup() throws IllegalStateException,    NoSuchElementException, FileNotFoundException
    {
    FileReader fr = new FileReader("Students.txt");
    //fr = new FileReader("Students.txt");
    Scanner sc = new Scanner(fr);
    /**
     * Creates another array group from subgroup and adds elements from the
     * text file to the subgroup.
     * Then adds the subgroup to group 0.
     */
    this.subgroup = new ArrayList<String>();
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    group.add(0, subgroup);

    /**
     * Creates another array group from subgroup and adds elements from the
     * text file to the subgroup.
     * Then adds the subgroup to group 1.
     */
    this.subgroup = new ArrayList<String>();
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    group.add(1, subgroup);

    /**
     * Creates another array group from subgroup and adds elements from the
     * text file to the subgroup.
     * Then adds the subgroup to group 2.
     */
    this.subgroup = new ArrayList<String>();
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    group.add(2, subgroup);

    /**
     * Creates another array group from subgroup and adds elements from the
     * text file to the subgroup.
     * Then adds the subgroup to group 3.
     */
    this.subgroup = new ArrayList<String>();
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    subgroup.add(sc.next());
    group.add(3, subgroup);
    /**
     * Executes the method SOP
     */
    this.SOP();
    /**
     * Closes the scanner
     */
    sc.close();
    }

    /**
     * This method shuffles the group array list and outputs the group numbers
     * with the group names till all are in groups.
     */
    public void SOP()
    {

       Collections.shuffle(group);
       for (int i = 0; i < group.size(); i++)
       {
        System.out.println("Group #" + (i+1));
        for (int j = 0; j < group.get(i).size(); j++)
        {
            System.out.println(group.get(i).get(j));
        }
        System.out.println();
       }
    }

    public static void main(String[] args) throws FileNotFoundException
    {
    /**
     * Executes the method groupAndSubgroup
     */
    RandomGroup rg = new RandomGroup();
    rg.groupAndSubgroup();
    }

}

Thank you

Answers


If I understand what do you want to do, you can try this:

List<String> groups = new ArrayList<String>();

Collections.shuffle(groups);

Where, Collection is a java class..

This is Documentation, an extract is :

public static void shuffle(List list)

Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood.


Need Your Help

would this procedure calculate the no of rows ? how do i call this procedure from php?

php mysql

test1 is procedure which counts rows of table which is being created after passing two variables v_col1 and v_col2. when I run this on MySQL, it shows

PHP calendar start week with monday ( offset )

php calendar offset

I am creating class for calendar where I create simple month preview.