Peer Value Distributer
Given an array, return a new array with the same keys and values distributed
randomly and evenly amongst the peers in the specified batch quantity., (*1)
, (*2)
For example, say you have a group of 15 book authors. You want each author to
review 3 of their peers' work. This function will randomly assign each
author 3 of its peers to read., (*3)
- Every book is reviewed exactly 3 times.
- No one will review any book more than once.
- No one will review their own book.
The natural maximum distribution count is n-1
so if you specify a count larger than that,
it will be ignored and the largest possible count will be used instead., (*4)
e.g. if you distribute those 15 books with a count of 20,
it will be ignored and instead every author will be assigned the maximum
of 14 peer books to review., (*5)
Registered on packagist for easy installation using composer., (*6)
composer require jpuck/peer-value-distributer
Example
use jpuck\PeerValueDistributer;
$books = [
'John' => 'The Book of John',
'Jane' => 'A Work by Jane',
'Jeff' => 'Readings from Jeff',
'Jose' => 'Words of Jose',
'Jena' => 'Writing with Jena',
];
print_r( PeerValueDistributer::distribute($books, $count = 3) );
Output:, (*7)
Array
(
[Jena] => Array
(
[John] => The Book of John
[Jeff] => Readings from Jeff
[Jane] => A Work by Jane
)
[John] => Array
(
[Jeff] => Readings from Jeff
[Jane] => A Work by Jane
[Jose] => Words of Jose
)
[Jeff] => Array
(
[Jane] => A Work by Jane
[Jose] => Words of Jose
[Jena] => Writing with Jena
)
[Jane] => Array
(
[Jose] => Words of Jose
[Jena] => Writing with Jena
[John] => The Book of John
)
[Jose] => Array
(
[Jena] => Writing with Jena
[John] => The Book of John
[Jeff] => Readings from Jeff
)
)