<?php // $countAfter[$i][$j] will contain the number of occurrences of a pair $i, $j in the randomly generated sequence $countAfter = [1 => [1 => 0, 2 => 0], 2 => [1 => 0, 2 => 0] ]; $prev = 1; // We assume for simplicify that the "previously" generated value was 1 for ($i = 0; $i < 10000; $i++) { $n = mt_rand(1, 2); $countAfter[$prev][$n]++; $prev = $n; } print_r($countAfter);
You have javascript disabled. You will not be able to edit any code.