I'm trying to make a randomizing roster. I am having trouble with it.
I need to take 1 C 2 P SS CF 3 LF RF
And create 9 random orders where they do not repeat in order, nor does one value take the same spot twice. Like a grid where each position is used once 9 times up and 9 times across. But I want to be able to randomize it. So its not always the same. I mean I guess I could just randomize the names, but the names would typically be in a specific order, whereas the positions would need not be, but not duped.
123456789
234567891
345678912
456789123
567891234
678912345
789123456
891234567
912345678
I started with this, but it makes no sense. At first I was making sure as to not duplicate any positions, but I realized it didn't really, and I got kinda brain stuck.
shuffle($positions);
$p1 = $positions;
echo '<table style="width:100%;"><tr>';
foreach($p1 as $pA){
echo '<td>'.$pA.'</td>';
}
echo '</tr>';
shuffle($positions);
$p2 = $positions;
if($p2 === $p1){
while($p2 === $p1){
shuffle($positions);
$p2 = $positions;
$a++;
echo '<br>=a=<br>'.$a.'<br>==<br>';
//if($p2 == $p1){continue;}else{break;}
}
}
echo '<tr>';
foreach($p2 as $pB){
echo '<td>'.$pB.'</td>';
}
echo '</tr>';
shuffle($positions);
$p3 = $positions;
if($p3 === ($p1 || $p2)){
while($p3 === ($p1 || $p2)){
shuffle($positions);
$p3 = $positions;
$b++;
echo '<br>=b=<br>'.$b.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p3 as $pC){
echo '<td>'.$pC.'</td>';
}
echo '</tr>';
shuffle($positions);
$p4 = $positions;
if($p4 === ($p1 || $p2 || $p3)){
while($p4 === ($p1 || $p2 || $p3)){
shuffle($positions);
$p4 = $positions;
$c++;
echo '<br>=c=<br>'.$c.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p4 as $pD){
echo '<td>'.$pD.'</td>';
}
echo '</tr>';
shuffle($positions);
$p5 = $positions;
if($p5 === ($p1 || $p2 || $p3 || $p4)){
while($p5 === ($p1 || $p2 || $p3 || $p4)){
shuffle($positions);
$p5 = $positions;
$d++;
echo '<br>=d=<br>'.$d.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p5 as $pE){
echo '<td>'.$pE.'</td>';
}
echo '</tr>';
shuffle($positions);
$p6 = $positions;
if($p6 === ($p1 || $p2 || $p3 || $p4 || $p5)){
while($p6 === ($p1 || $p2 || $p3 || $p4 || $p5)){
shuffle($positions);
$p6 = $positions;
$e++;
echo '<br>=d=<br>'.$e.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p6 as $pF){
echo '<td>'.$pF.'</td>';
}
echo '</tr>';
shuffle($positions);
$p7 = $positions;
if($p7 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6)){
while($p7 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6)){
shuffle($positions);
$p7 = $positions;
$f++;
echo '<br>=d=<br>'.$f.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p7 as $pG){
echo '<td>'.$pG.'</td>';
}
echo '</tr>';
shuffle($positions);
$p8 = $positions;
if($p8 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7)){
while($p8 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7)){
shuffle($positions);
$p8 = $positions;
$g++;
echo '<br>=d=<br>'.$g.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p8 as $pH){
echo '<td>'.$pH.'</td>';
}
echo '</tr>';
shuffle($positions);
$p9 = $positions;
if($p9 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7 || $p8)){
while($p9 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7 || $p8)){
shuffle($positions);
$p9 = $positions;
$h++;
echo '<br>=d=<br>'.$h.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p9 as $pI){
echo '<td>'.$pI.'</td>';
}
echo '</tr>';
shuffle($positions);
$p10 = $positions;
if($p10 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7 || $p8 || $p9)){
while($p10 === ($p1 || $p2 || $p3 || $p4 || $p5 || $p6 || $p7 || $p8 || $p9)){
shuffle($positions);
$p10 = $positions;
$i++;
echo '<br>=d=<br>'.$i.'<br>==<br>';
//if($p2 == ($p1 || $p2)){continue;}else{break;}
}
}
echo '<tr>';
foreach($p10 as $pJ){
echo '<td>'.$pJ.'</td>';
}
echo '</tr>';
echo '</table>';
?>