Sign in Forgot Password?
0 Members and 3 Guests are viewing this topic.10109 views
What's the pot at at the moment?
<?phpheader('Content-Type: text/plain; charset=utf-8');//Participants and number of tickets$participants = array( "Mini Nub" => 5, "Justin" => 5, "Sveiks" => 5, "Sean202" => 5, "Ryus" => 5, "Lipsync" => 5, "Altys" => 5, "eSmurfie" => 5, "George" => 1, "Lucie" => 5, "Physh" => 5, "Matty" => 1, "PH1L" => 2, "XaM" => 5, "Lilly" => 5, "Powell" => 5, "Monochrome" => 5, "Skill orion" => 5, "Proud Winter" => 2, "SheepProbe" => 5, "Zync0nfiah" => 5);$max = array_sum($participants)+1;//Run this once, works for ticket count up to 255function generateNumbers($participants, $max) { $numbers = array(); $t = array(0); foreach($participants as $name => $tickets) { while($tickets > 0) { $number = rng($max, $t); $t[] = $number; $numbers[$name][] = $number; $tickets--; } } return $numbers;}//Simply redraw if the same player gets a winning number more than oncefunction drawWinner($max, $mask = "\x7f") { $n = false; while(!$n) { $byte = openssl_random_pseudo_bytes(1) & $mask; if(ord($byte) < $max && ord($byte) > 0) { $n = true; } } return ord($byte);}function rng($max, $taken, $mask = "\x7f") { $n = false; while(!$n) { $byte = openssl_random_pseudo_bytes(1) & $mask; if(ord($byte) < $max && !in_array(ord($byte), $taken)) { $n = true; } } return ord($byte);}$num = generateNumbers($participants, $max);$out = "";foreach($num as $k => $v) { $out .= $k.":"; foreach($v as $n) { $out .= " ".$n.","; } $out = rtrim($out, ",")."\n";}echo $out;?>