array ( 'id' => 2, 'nome' => 'ANA SOCIAL G1', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 1 => array ( 'id' => 3, 'nome' => 'BRUNO PCD G2', 'is_social_benefit' => false, 'is_pcd' => true, 'is_nearby' => false, 'has_siblings' => false, ), 2 => array ( 'id' => 4, 'nome' => 'CARLA PROXIMO G3', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 3 => array ( 'id' => 5, 'nome' => 'DIEGO IRMAOS G4', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => true, ), 4 => array ( 'id' => 6, 'nome' => 'ERIK AMPLA G5', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 5 => array ( 'id' => 7, 'nome' => 'FABIO AMPLA G5', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 6 => array ( 'id' => 8, 'nome' => 'GABI SOCIAL E PCD G1', 'is_social_benefit' => true, 'is_pcd' => true, 'is_nearby' => false, 'has_siblings' => false, ), 7 => array ( 'id' => 9, 'nome' => 'HELCIO PROX E IRM G3', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => true, ), 8 => array ( 'id' => 10, 'nome' => 'IARA AMPLA G5', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 9 => array ( 'id' => 11, 'nome' => 'JOAO AMPLA G5', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 10 => array ( 'id' => 12, 'nome' => 'WILLAMS SILVA ANDRADE', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 11 => array ( 'id' => 13, 'nome' => 'WILLAMS SILVA ANDRADE', 'is_social_benefit' => false, 'is_pcd' => true, 'is_nearby' => false, 'has_siblings' => false, ), ); function fisherYatesShuffle(array $items, $groupSeed) { $n = count($items); if ($n <= 1) return $items; $hashedSeed = hash('sha256', $groupSeed); for ($i = $n - 1; $i > 0; $i--) { $hash = hash_hmac('sha256', $i . $hashedSeed, $hashedSeed); $j = hexdec(substr($hash, 0, 8)) % ($i + 1); $temp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $temp; } return $items; } // SEPARAÇÃO DOS GRUPOS (IGUAL AO NOVO LOTTERYSERVICE) $g1 = []; $g2 = []; $g3 = []; $g4 = []; $g5 = []; foreach ($candidatos as $c) { // ALTERADO: PCD passa a ser a primeira verificação (Prioridade 1) if ($c['is_pcd']) { $g1[] = $c; } // ALTERADO: Social passa a ser a segunda verificação (Prioridade 2) elseif ($c['is_social_benefit']) { $g2[] = $c; } elseif ($c['is_nearby']) { $g3[] = $c; } elseif ($c['has_siblings']) { $g4[] = $c; } else { $g5[] = $c; } } echo "--- PROCESSANDO SORTEIO POR PRIORIDADES (NOVA HIERARQUIA) ---\n"; echo "G1: PCD | G2: SOCIAL | G3: PROXIMIDADE | G4: IRMÃOS | G5: AMPLA\n\n"; $r1 = fisherYatesShuffle($g1, $sementeBase . '_g1'); $r2 = fisherYatesShuffle($g2, $sementeBase . '_g2'); $r3 = fisherYatesShuffle($g3, $sementeBase . '_g3'); $r4 = fisherYatesShuffle($g4, $sementeBase . '_g4'); $r5 = fisherYatesShuffle($g5, $sementeBase . '_g5'); $resultadoFinal = array_merge($r1, $r2, $r3, $r4, $r5); echo "LISTA FINAL AUDITADA:\n"; foreach ($resultadoFinal as $index => $c) { echo sprintf("%03dº | %-30s | ID: %d\n", $index + 1, $c['nome'], $c['id']); }