| |

VerySource

 Forgot password?
 Register
Search
View: 696|Reply: 2

Anxious, everyone prawns, find the algorithm for random assignment in the test room

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 06:40:01
| Show all posts |Read mode
Select a certain grade, such as the first grade (300 in total), and then select the scope of the test room (such as 301, 302, 303, .... a total of ten test rooms (first 30 test rooms each, some test rooms may add several people according to the actual situation)
How to allocate these 300 people to the ten test venues, grade individuals, and test range are all stored in the ArrayList. You can use a for loop to iterate or iterate to obtain its value. How to use random assignment (randomly assign candidates to the above test venues), or Other methods
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-18 14:45:01
| Show all posts
import java.util. *;


class Student {
  int id;
  public Student (int id) {
    this.id = id;
  }
}

class Classroom {
  int id;
  ArrayList list = new ArrayList ();
  public Classroom (int id) {
    this.id = id;
  }
  public void addStudent (Student st) {
    list.add (st);
  }
  public String toString () {
    StringBuffer sb = new StringBuffer ();
    sb.append ("Room id:" + id);
    sb.append ("\r\n");
    sb.append ("student:");
    for (int i = 0; i <list.size (); i ++) {
      Student st = (Student) list.get (i);
      sb.append (st.id + ",");
    }
    return sb.toString ();
  }
}

public class Test {
  public static void main (String args []) {
    ArrayList stList = new ArrayList ();
    ArrayList crList = new ArrayList ();
    for (int i = 0; i <300; i ++) {
      stList.add (new Student (i));
    }
    Collections.shuffle (stList);
    for (int i = 0; i <10; i ++) {
      crList.add (new Classroom (i));
    }
    for (int i = 0; i <stList.size (); i ++) {
      Student st = (Student) stList.get (i);
      Classroom cr = (Classroom) crList.get (i% crList.size ());
      cr.addStudent (st);
    }
    for (int i = 0; i <crList.size (); i ++) {
      Classroom cr = (Classroom) crList.get (i);
      System.out.println (cr);
    }
  }
}
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-21 22:45:01
| Show all posts
The general idea should be to randomly generate 30 people and then go to point 30. Random 30 people is a recursion. It is best to make the array seem to have a method of randomly generating subscripts.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list