Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a problem and I'm not to sure about how to go about handling it.

I have a group a students in a school management database that I need to randomly assign to pre-defined groups. I've done a lot of research on group assignment but I can't quite find what I'm looking for.

Basically, a student can be a member of a multiple groups. For example Tom can be a member of the Tennis_club as well as the CS_dept and the LARP_club, while Alex may only be a member of the CS_dept.

What I have tried:

My first idea was to generate a random number between 1 and 4 for example, representing the number of groups a student is to be a member of. Let's say the number 2 is returned. I then generate another random number between 1 and 20 (the number of groups I've defined) 2 times, and assign the student to the 2 groups of the numbers returned between 1 and 20. This will be done for each student in the database.

This is my idea but I'm not sure if it's the best way to go about it considering the number of students currently in the database. Any ideas?
Posted
Comments
Kornfeld Eliyahu Peter 1-Jan-18 3:56am    
If I understand correctly, you already have a table with students and an other with groups and you have to create - randomly - some connection between the two...
As the connection to be made (and the number of connections too) should be random, I can't see a better approach than loop with randoms in the way you described it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900