Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2.     /* Gero o Hexadecimal */
  3.     function randomHex() {
  4.         $chars = 'ABCDEF0123456789';
  5.         $color = '#';
  6.         for ( $i = 0; $i < 6; $i++ ) {
  7.             $color .= $chars[rand(0, strlen($chars) - 1)];
  8.         }
  9.         return $color;
  10.     }
  11.  
  12.     // Dados Necessários Para o Sorteio...
  13.     $nump='32';        // Numero de Participantes
  14.  
  15.     // Chamo a Funcao
  16.     $sorteio=random($nump,1);
  17.  
  18.     function random($nNumeros, $nQuant) {
  19.  
  20.         $aRand = array();
  21.        
  22.         for ($i=1; $i<=$nQuant; $i++) {
  23.            
  24.             $aRand[$i] = $rand = randomHex();
  25.  
  26.             while (count($aRand) < $nNumeros)
  27.                 if (!in_array($rand, $aRand))
  28.                     $aRand[] = $rand;
  29.                 else
  30.                     $rand = randomHex();
  31.             }
  32.         return $aRand;
  33.    
  34.     }
  35.  
  36.  
  37.      echo "<pre>";
  38.      print_r($sorteio);
  39.      echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement