public static List < Integer > getUniformCounts ( final int elementCount , final int taskCount ) { final int quotient = elementCount / taskCount ; final int remainder = elementCount % taskCount ; final List < Integer > retList = new ArrayList <> ( ) ; for ( int taskIndex = 0 ; taskIndex < taskCount ; taskIndex ++ ) { if ( taskIndex < remainder ) { retList . add ( quotient + 1 ) ; } else { retList . add ( quotient ) ; } } return retList ; }
Uniformly distribute a number of elements across a number of Tasks and return a list of counts . If uniform distribution is impossible then some Tasks will receive one more element than others . The sequence of the number of elements for each Task is non - increasing .