Skip to content

Randomizer::pickArrayKeys() has intransparent external behavior #1731

Open
@TimWolla

Description

@TimWolla

Description

The following code:

<?php

$r1 = new Random\Randomizer(new Random\Engine\Xoshiro256StarStar(1));
$r2 = new Random\Randomizer(new Random\Engine\Xoshiro256StarStar(1));

$a = [ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, ];
unset($a['b']);

$b = [ 'a' => 1, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, ];

var_dump($a === $b); // bool(true)

var_dump(
	$r1->pickArrayKeys($a, 1), // [ 0 => 'e' ]
	$r2->pickArrayKeys($b, 1), // [ 0 => 'd' ]
);

Resulted in this output:

bool(true)
array(1) {
  [0]=>
  string(1) "e"
}
array(1) {
  [0]=>
  string(1) "d"
}

But I expected this output instead:

The same key selected, because the arrays are identical.

PHP Version

Current git master

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions