Python Forum
Random student selection from groups.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random student selection from groups.
#1
There are students in different groups according to their grade levels. I want to make a selection so that students in the same grade level do not come together.

For examlple:

Group 9 : 120 students
Group 10 : 175 students
Group 11 : 90 students
Group 12 : 210 students


All students in the groups will be selected randomly. But same group not come together. if I selected randomly, students from group 12 are staying.

I don't want this:

Random Result:
1 - Group 9 student 1
2 - Group 10 student 1
3 - Group 10 Student 2
Reply
#2
What have you tried? Can you provide more information about what you want to achieve? Will the student groups be size 3 like your example, one student per group, or different sized groups. Will you ever have a group of 5 students or more?

The obvious solution for not selecting two students from the same grade level is to make that impossible. If you pick a grade 9 student, don't have any grade 9 students in the pool for picking the next student. I can think of two ways to do this.
Reply
#3
There are 595 students in my school.

Grade 9 : 120 student
Grade 10 : 175 student
Grade 11 : 90 student
Grade 12 : 210 student


Sum : 595 students

I will create a list from this student (all students). I will do exam seating arrangement. Same grade will not sit next to each other. I want to develop an algorithm because the number of students in the group is different.

my list should be (random selection) :

1) grade 9 student 1
2) grade 12 student 195
3) grade 10 student 78
4) grade 12 student 210
5) grade 11 student 65
...
595) grade 12 student 193
Reply
#4
I suggest to take the first student in the most numerous group, then always take a student in the most numerous remaining group different from the last student chosen.
I tested this algorithm and it worked for these numbers.
Obviously, there is not always a solution. If you had 1 student in each grade and 592 in grade 12, the problem would be impossible.
« We can solve any problem by introducing an extra level of indirection »
Reply
#5
There is no obligation to choose from each group in turn. Only those in the same group will not take turns.
Reply
#6
(Jul-03-2024, 04:32 PM)esahan Wrote: There is no obligation to choose from each group in turn. Only those in the same group will not take turns.
Is this homework? In that case we could move this to the homework forum. Have you written some code?
I implemented my strategy with the heapq module.

Now I see a second strategy. It seems to me that the problem has a solution if and only if the size of the largest grade group is smaller than the sum of the sizes of the other groups. One could try to keep this invariant during the process of choosing the students.

Of course, within each grade group we can choose students randomly.
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
Grade 9 : 120 student
Grade 10 : 175 student
Grade 11 : 90 student
Grade 12 : 210 student

Make 90 groups of 4, Grade 11 gone
Grade9 = 120 - 90 = 30
Grade10 = 175 - 90 = 85
Grade12 = 210 - 90 = 120
Make 30 groups of 3, Grade9 gone
Grade10 = 85 - 30 = 55
Grade12 = 120 - 30 = 90
Make 55 groups of 2 , Grade10 gone
Grade12 = 90 - 55 = 35
These guys must form 35 groups of 1 in order to not sit with a student of the same year.

Total (groups, number of students):
(90,4)
(30,3)
(55,2)
(35,1)

In all: 90 + 30 + 55 + 35 = 210 groups

You see the strategy.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to group related products in relationship groups? RegionHUser 2 335 Jun-02-2024, 03:51 PM
Last Post: Pedroski55
  Ldap Search for finding user Groups ilknurg 1 1,930 Mar-11-2022, 12:10 PM
Last Post: DeaD_EyE
  how do I return Max Test result + corresponding student name from an excel dataset? sean1 3 1,403 Jan-16-2022, 09:07 PM
Last Post: snippsat
  Make Groups with the List Elements quest 2 2,099 Jul-11-2021, 09:58 AM
Last Post: perfringo
  Understanding Regex Groups matt_the_hall 5 3,040 Jan-11-2021, 02:55 PM
Last Post: matt_the_hall
  How to solve equations, with groups of variables and or constraints? ThemePark 0 1,772 Oct-05-2020, 07:22 PM
Last Post: ThemePark
  Create homogeneous groups with Kmeans ? preliator 0 1,640 Sep-01-2020, 02:29 PM
Last Post: preliator
  Regex: finding if three groups have a value in them Daring_T 7 3,597 May-15-2020, 12:27 AM
Last Post: Daring_T
  How to take group of numbers summed in groups of 3... jaguare22 1 1,625 May-05-2020, 05:23 AM
Last Post: Yoriz
  Listing groups tharpa 2 2,714 Nov-26-2019, 07:25 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020