The easiest method
- Create an array with 29 elements
- Add account IDs as many times as a lesson. for 4 teachers, their IDs are added to this array 2 times, and for 7 teachers, 3 times.
- mix this array. It is necessary to rearrange the elements randomly.
- Optionally, you can add a check for the next identical ID. What would 2 ID in a row did not come. if so, swap 2nd identical ID followed by
- you have an array ready. each array index is a day on the calendar
Option number 2
show in the example
1) there is data
4 Teacher * 2 lessons = 8 - let them be (1,2,3,4)
7 Teacher * 3 lessons = 21 - let them be (5,6,7,8,9,10,11)
2) create 2 arrays from A [4] and B [7] elements. Fill the first with elements (1,2,3,4) and the second with (5,6,7,8,9,10,11)
3) create arrays C [8] and D [21]
4) Shuffle array A and add it to array C. Do it 2 times. We also do for arrays B and D only 3 times.
For example:
A[] = {1,2,3,4} A[перемешка] = {4,1,3,2} C[] = {4,1,3,2} A[перемешка] = {2,4,3,1} C[] = {4,1,3,2,2,4,3,1} B[] = {5,6,7,8,9,10,11} B[перемешка] = {5,6,7,8,9,10,11} D[] = {5,6,7,8,9,10,11} B[перемешка] = {9,10,5,6,7,8,11} D[] = {5,6,7,8,9,10,11,9,10,5,6,7,8,11} B[перемешка] = {8,9,10,11,5,6,7} D[] = {5,6,7,8,9,10,11,9,10,5,6,7,8,11,8,9,10,11,5,6,7}
3) now need to collect. for this we need an array of X [29] now we take randomly from 2 arrays and add an array of X []
Example
C[] = {4,1,3,2,2,4,3,1} D[] = {5,6,7,8,9,10,11,9,10,5,6,7,8,11,8,9,10,11,5,6,7} X[] = {5,6,4,7,1,3,8,2,9,10,2,11,9,4,10,5,6,7,3,8,11,8,9,1,10,11,5,6,7}