mercredi 2 décembre 2020

randomizing numbers 1 & 2 so that when they occur twice they are a differnet number

i'm basically randomizing two players so that the randomness is not totally random. For instance, if they took turns, the rng would not allow a player to be their turn for more then 2 times/turns in a row.

What I've current got:

$playerV = $_POST["playerV"];
    $ranplayer = random_int(1, $playerV);
    $ranplayer2 = random_int(1, $playerV);
    // change the player number if they the same
    if ($ranplayer = $ranplayer2) {
        $upplayer = --$ranplayer;
        if ($upplayer == 0) {
            $upplayer = $upplayer + 2;
        }
    }
  $a = $upplayer;
    $b = array_push($z, "$a");
    if ($b == $a) {
        $c += 1;
        echo $upplayer;
        echo '/';
        echo $ranplayer2;
        echo '/';
        echo "this is c=ba->".$c;
    }
else {
        $c += 0;
        echo $upplayer;
        echo '/';
        echo $ranplayer2;
        echo '/';
        echo "this is c=el->".$c;
    }
    }

this code works but its very unreliable.




Aucun commentaire:

Enregistrer un commentaire