jpuck / peer-value-distributer
给定一个数组,返回一个具有相同键和值的数组,这些键和值在指定的批量数量中随机均匀地分配给指定的批次中的参与者。
1.0.1
2017-01-28 22:35 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-24 23:51:36 UTC
README
给定一个数组,返回一个新的数组,其中具有相同键和值的键和值在指定的批量数量中随机均匀地分配给参与者。
例如,假设你有一个由15位图书作者组成的群体。你希望每位作者审阅他们3位同伴的作品。此函数将随机分配每位作者阅读其3位同伴的作品。
- 每本书正好被审阅3次。
- 没有人会审阅任何一本书不止一次。
- 没有人会审阅自己的书。
自然最大分布计数是 n-1
,所以如果你指定的计数大于该值,它将被忽略,并使用最大可能的计数。
例如,如果你用20个计数分发这15本书,它将被忽略,相反,每位作者将被分配最大14本同伴书籍进行审阅。
注册于 packagist,以便使用 composer 方便安装。
composer require jpuck/peer-value-distributer
示例
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) );
输出
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 ) )