Skip to content

Instantly share code, notes, and snippets.

@bagart
Created October 7, 2021 19:41
Show Gist options
  • Save bagart/4140b1d2d74c38a8f021fd26d32de91c to your computer and use it in GitHub Desktop.
Save bagart/4140b1d2d74c38a8f021fd26d32de91c to your computer and use it in GitHub Desktop.
random3.php
<?php
$xcount = [0 => 0, 1 => 0, 2 => 0];
for ($i0 = 0; $i0 < 3*333; ++$i0) {
for ($i1 = 0; $i1 < 2; ++$i1) {
for ($i2 = 0; $i2 < 2; ++$i2) {
for ($i3 = 0; $i3 < 2; ++$i3) {
for ($i4 = 0; $i4 < 2; ++$i4) {
for ($i5 = 0; $i5 < 2; ++$i5) {
for ($i6 = 0; $i6 < 2; ++$i6) {
++$xcount[random3(rr3x3($i1, $i2, $i3, $i4, $i5, $i6))];
}}}}}}
}
var_dump($xcount);
$xcount = [0 => 0, 1 => 0, 2 => 0];
$x = 500 * 3 * (2 * 2 * 2 * 2 * 2 * 2);
while ($x--) {
++$xcount[random3(
rr3x3(
random2(),
random2(),
random2(),
random2(),
random2(),
random2()
)
)];
}
var_dump($xcount);
/**
* @return 0|1|2
*/
function random3($x): int
{
$num = (int) "{$x[0]}{$x[1]}{$x[2]}";
static $mem = 0;
if ($num === 111) {
if (++$mem % 2) {
$num = $mem;
}
if ($mem === 6) $mem = 0;
}
return $num % 3;
}
//1,1,1
//1,1,2
//1,1,3
//всегда полная равнораспределенная комбинация 1-2-3 в каждом регистре
function rr3x3($i1, $i2, $i3, $i4, $i5, $i6): array
{
$x1 = 1 + $i1 + $i2;
$x2 = 1 + $i3 + $i4;
$x3 = 1 + $i5 + $i6;
if ($x2 === 2) {
$x2 = 1;
} elseif ($x2 === 1) {
$x2 = 2;
}
if ($x3 === 2) {
$x3 = 3;
} elseif ($x3 === 3) {
$x3 = 2;
}
return [$x1, $x2, $x3];
}
function random2(): int
{
return random_int(0, 1);
}
@bagart
Copy link
Author

bagart commented Oct 7, 2021

https://3v4l.org/vdWjE#v8.0.11

array(3) {
[0]=>
int(21312)
[1]=>
int(21312)
[2]=>
int(21312)
}
array(3) {
[0]=>
int(32008)
[1]=>
int(31935)
[2]=>
int(32057)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment