I have read the answers to the Slicing a list into n nearly-equal-length partitions [duplicate] question.
This is the accepted answer:
def partition(
First you randomize the list and then you split it in n nearly equal parts.