The basic idea is that if you have any number of students, you pick the last one and roll a dice with the same number of sides as the remaining students to see who they are paired with. Then you keep removing paired students and roll for those that remain. so if you had ten, you'd roll a d9, then a d7, then a d5, then a d3.