Split list into even parts

Hi, I’m making an app for classroom teachers. I want to create a system where the teacher can break their class up into X number of groups (where the teacher inputs the value of X). Students would be randomly assigned to a group. I’d then like the teacher to be able to give a group mark (that is applied to all students in the group).

I have ‘students’ as a data type and can easily generate a random list of all relevant students (i.e. in the right class, and marked as ‘attending’), but I don’t know how to split that list into smaller lists, or filter it, based on the number of groups the teacher wants. Can anyone help me figure out how to split a list into roughly even sections? Or point me in the right direction?

Thanks

Barry