<?php function randomizer($sArray, $target) { $b = (count($sArray)/2); // Randomize count for better result make it half of the total array count $c = floor($target/$b); // Loop Count $r = $target-($b*$c); // Rest of the Count $cardsList = array(); if($c > 0){ /* Now Loop for Full Number */ for($i=0; $i<$c; $i++){ $cardsList = array_merge($cardsList,array_rand($sArray, $b)); } if($r >= 1){ $restArray = array_rand($sArray, $r); if(is_array($restArray)){ $cardsList = array_merge($cardsList,$restArray); }else{ $cardsList[] = $restArray; } } }else{ $cardsList = array_merge($cardsList,array_rand($sArray, $target)); } return $cardsList; } //only 8 values $sArray = range('A', 'H'); $resultArray = randomizer($sArray, 67); echo 'Amount 50 - result: ' . count($resultArray) . \PHP_EOL; print_r($resultArray);
You have javascript disabled. You will not be able to edit any code.