Within your while loop, $p1, $fin, $fin2, and $p2 are just static values that you've set in your earlier code. If you want any/all of them to vary each time through the loop, then you'll need to call the relevant function or otherwise do the processing within the loop:
while($x++ < 999) // use ++ increment operator to save a line of code :)
{
$string = rand(0,9) . $dash . randomkeys($n) . $dash . randomkeys($m) . $dash . rand(0,9);
echo "<br>$string<br>\n";
}