array ( 'id' => 6, 'nome' => 'ALANNA DE OLIVEIRA RODRIGUES', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 1 => array ( 'id' => 7, 'nome' => 'ANNA VITÓRIA SUZANO MOTA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 2 => array ( 'id' => 54, 'nome' => 'JOAQUIM EMANUEL CARDOSO LOIOLA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 3 => array ( 'id' => 63, 'nome' => 'RYAN RIBEIRO TRINDADE', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 4 => array ( 'id' => 65, 'nome' => 'LAERTE DA SILVA ALMEIDA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 5 => array ( 'id' => 77, 'nome' => 'MATHIAS DAS NEVES FERREIRA RREIRA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 6 => array ( 'id' => 83, 'nome' => 'AYLA MARIA SANTOS DA SILVA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 7 => array ( 'id' => 113, 'nome' => 'MARIA CECILIA GONÇALVES DA SILVA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 8 => array ( 'id' => 126, 'nome' => 'MARIA CLARA SILVA BISPO', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 9 => array ( 'id' => 130, 'nome' => 'GABRIEL CARDOSO LIMA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 10 => array ( 'id' => 162, 'nome' => 'MARIA JÚLIA LOIOLA TELES', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 11 => array ( 'id' => 165, 'nome' => 'LUNA SANTANA LIMA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 12 => array ( 'id' => 173, 'nome' => 'BRAYAN DA SILVA SIRINO', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 13 => array ( 'id' => 175, 'nome' => 'JENNIFFER EMANUELLEN PEREIRA DIAS', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 14 => array ( 'id' => 190, 'nome' => 'ASAEL SILVA SANTOS', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 15 => array ( 'id' => 219, 'nome' => 'AGATHA EVANGELISTA DE SOUZA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => true, ), 16 => array ( 'id' => 226, 'nome' => 'MARIANA JESUS ALMEIDA', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 17 => array ( 'id' => 229, 'nome' => 'BENÍCIO LOIOLA DA SILVA', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 18 => array ( 'id' => 249, 'nome' => 'EZEQUIEL ALVES BASTOS', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 19 => array ( 'id' => 254, 'nome' => 'EMANUELLY CARVALHO FELIX', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 20 => array ( 'id' => 257, 'nome' => 'MARIA FLOR FELIX BEZERRA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 21 => array ( 'id' => 258, 'nome' => 'MARIA LIZ FERREIRA RIBEIRO', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => false, ), 22 => array ( 'id' => 259, 'nome' => 'HENRY LUCCA LOIOLA DOS SANTOS', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => true, 'has_siblings' => true, ), 23 => array ( 'id' => 298, 'nome' => 'RAVI LUCCA NUNES RIBEIRO', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 24 => array ( 'id' => 304, 'nome' => 'LARA LIZ DOS SANTOS SILVA', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 25 => array ( 'id' => 314, 'nome' => 'NICOLAS BENTO FURQUIM ELPIDIO', 'is_social_benefit' => true, 'is_pcd' => false, 'is_nearby' => false, 'has_siblings' => false, ), 26 => array ( 'id' => 321, 'nome' => 'ANTÔNIO CARDOSO LIMA', 'is_social_benefit' => false, 'is_pcd' => false, 'is_nearby' => true, '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']); }