Created
May 3, 2015 15:19
-
-
Save ashfame/d41acf0a32ca85e2267d to your computer and use it in GitHub Desktop.
Simple algorithm for picking up 3-7 preferred nodes for each node among a pool of nodes, so that its a little uneven (every node has different number of preferred nodes) but overall there is a balance in distribution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nodes = array(); | |
for ( $i = 1; $i <= 100; $i++ ) { | |
$nodes[ $i ] = ''; | |
} | |
print_r( $nodes ); | |
foreach ( $nodes as $key => &$node ) { | |
$random_keys_selection = array_rand( $nodes, mt_rand( 3, 7 ) ); | |
var_dump( $random_keys_selection ); | |
$node[ $key ] = implode( ',', $random_keys_selection ); | |
} | |
print_r( $nodes ); |
Author
ashfame
commented
May 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment