<?php

$joins = $_GET["joins"];
$joinRate = $_GET["joinrate"];

$commands = array();
$nextLeaveNumber = 2;
$joinCount = 0;

while($joinCount < $joins) {
    if (rand(0, 100) < $joinRate * 100) {
        array_push($commands, "J");
        $joinCount++;        
    } else if ($nextLeaveNumber < $joinCount){
        array_push($commands, "L".$nextLeaveNumber++);
    } 
}
echo "commands.txt\n";

foreach ($commands as $value) {
    echo $value."\n";
}

echo "commands.js\n{";
foreach ($commands as $value) {
    echo "\"".$value."\",";
}
echo "}\n";
print_r($commands);
?>
