Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashfame/d41acf0a32ca85e2267d to your computer and use it in GitHub Desktop.
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.
$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 );
@ashfame
Copy link
Author

ashfame commented May 3, 2015

Array
(
    [1] => 
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => 
    [11] => 
    [12] => 
    [13] => 
    [14] => 
    [15] => 
    [16] => 
    [17] => 
    [18] => 
    [19] => 
    [20] => 
    [21] => 
    [22] => 
    [23] => 
    [24] => 
    [25] => 
    [26] => 
    [27] => 
    [28] => 
    [29] => 
    [30] => 
    [31] => 
    [32] => 
    [33] => 
    [34] => 
    [35] => 
    [36] => 
    [37] => 
    [38] => 
    [39] => 
    [40] => 
    [41] => 
    [42] => 
    [43] => 
    [44] => 
    [45] => 
    [46] => 
    [47] => 
    [48] => 
    [49] => 
    [50] => 
    [51] => 
    [52] => 
    [53] => 
    [54] => 
    [55] => 
    [56] => 
    [57] => 
    [58] => 
    [59] => 
    [60] => 
    [61] => 
    [62] => 
    [63] => 
    [64] => 
    [65] => 
    [66] => 
    [67] => 
    [68] => 
    [69] => 
    [70] => 
    [71] => 
    [72] => 
    [73] => 
    [74] => 
    [75] => 
    [76] => 
    [77] => 
    [78] => 
    [79] => 
    [80] => 
    [81] => 
    [82] => 
    [83] => 
    [84] => 
    [85] => 
    [86] => 
    [87] => 
    [88] => 
    [89] => 
    [90] => 
    [91] => 
    [92] => 
    [93] => 
    [94] => 
    [95] => 
    [96] => 
    [97] => 
    [98] => 
    [99] => 
    [100] => 
)
array (size=3)
  0 => int 57
  1 => int 62
  2 => int 75
array (size=5)
  0 => int 25
  1 => int 40
  2 => int 59
  3 => int 70
  4 => int 71
array (size=7)
  0 => int 24
  1 => int 34
  2 => int 48
  3 => int 52
  4 => int 55
  5 => int 71
  6 => int 94
array (size=7)
  0 => int 10
  1 => int 14
  2 => int 19
  3 => int 57
  4 => int 78
  5 => int 82
  6 => int 99
array (size=4)
  0 => int 3
  1 => int 4
  2 => int 61
  3 => int 84
array (size=6)
  0 => int 9
  1 => int 15
  2 => int 17
  3 => int 30
  4 => int 71
  5 => int 94
array (size=7)
  0 => int 4
  1 => int 7
  2 => int 17
  3 => int 33
  4 => int 34
  5 => int 70
  6 => int 86
array (size=4)
  0 => int 1
  1 => int 28
  2 => int 73
  3 => int 84
array (size=5)
  0 => int 53
  1 => int 61
  2 => int 73
  3 => int 77
  4 => int 100
array (size=6)
  0 => int 11
  1 => int 15
  2 => int 20
  3 => int 38
  4 => int 81
  5 => int 89
array (size=6)
  0 => int 52
  1 => int 56
  2 => int 73
  3 => int 78
  4 => int 86
  5 => int 99
array (size=5)
  0 => int 37
  1 => int 46
  2 => int 68
  3 => int 75
  4 => int 81
array (size=4)
  0 => int 26
  1 => int 49
  2 => int 91
  3 => int 92
array (size=7)
  0 => int 9
  1 => int 21
  2 => int 55
  3 => int 80
  4 => int 89
  5 => int 90
  6 => int 97
array (size=6)
  0 => int 6
  1 => int 10
  2 => int 27
  3 => int 40
  4 => int 48
  5 => int 53
array (size=7)
  0 => int 4
  1 => int 8
  2 => int 58
  3 => int 65
  4 => int 83
  5 => int 97
  6 => int 98
array (size=6)
  0 => int 9
  1 => int 36
  2 => int 37
  3 => int 40
  4 => int 62
  5 => int 89
array (size=3)
  0 => int 20
  1 => int 32
  2 => int 76
array (size=4)
  0 => int 25
  1 => int 39
  2 => int 43
  3 => int 54
array (size=5)
  0 => int 8
  1 => int 46
  2 => int 47
  3 => int 58
  4 => int 96
array (size=5)
  0 => int 29
  1 => int 36
  2 => int 58
  3 => int 68
  4 => int 73
array (size=6)
  0 => int 3
  1 => int 6
  2 => int 11
  3 => int 16
  4 => int 21
  5 => int 53
array (size=7)
  0 => int 9
  1 => int 10
  2 => int 80
  3 => int 91
  4 => int 93
  5 => int 96
  6 => int 97
array (size=3)
  0 => int 1
  1 => int 29
  2 => int 46
array (size=6)
  0 => int 11
  1 => int 15
  2 => int 20
  3 => int 35
  4 => int 58
  5 => int 99
array (size=3)
  0 => int 69
  1 => int 72
  2 => int 83
array (size=5)
  0 => int 37
  1 => int 44
  2 => int 49
  3 => int 64
  4 => int 66
array (size=4)
  0 => int 15
  1 => int 43
  2 => int 47
  3 => int 94
array (size=3)
  0 => int 7
  1 => int 71
  2 => int 82
array (size=3)
  0 => int 4
  1 => int 69
  2 => int 74
array (size=6)
  0 => int 16
  1 => int 23
  2 => int 42
  3 => int 44
  4 => int 60
  5 => int 83
array (size=7)
  0 => int 6
  1 => int 17
  2 => int 31
  3 => int 41
  4 => int 60
  5 => int 65
  6 => int 87
array (size=7)
  0 => int 12
  1 => int 28
  2 => int 34
  3 => int 41
  4 => int 46
  5 => int 53
  6 => int 62
array (size=3)
  0 => int 3
  1 => int 15
  2 => int 100
array (size=3)
  0 => int 37
  1 => int 54
  2 => int 89
array (size=4)
  0 => int 14
  1 => int 41
  2 => int 51
  3 => int 59
array (size=7)
  0 => int 19
  1 => int 21
  2 => int 40
  3 => int 48
  4 => int 53
  5 => int 73
  6 => int 83
array (size=6)
  0 => int 15
  1 => int 37
  2 => int 56
  3 => int 60
  4 => int 65
  5 => int 97
array (size=5)
  0 => int 23
  1 => int 40
  2 => int 59
  3 => int 92
  4 => int 97
array (size=4)
  0 => int 24
  1 => int 51
  2 => int 68
  3 => int 80
array (size=3)
  0 => int 11
  1 => int 52
  2 => int 81
array (size=5)
  0 => int 16
  1 => int 18
  2 => int 33
  3 => int 40
  4 => int 44
array (size=6)
  0 => int 28
  1 => int 31
  2 => int 41
  3 => int 61
  4 => int 72
  5 => int 87
array (size=3)
  0 => int 2
  1 => int 5
  2 => int 68
array (size=7)
  0 => int 31
  1 => int 32
  2 => int 33
  3 => int 72
  4 => int 78
  5 => int 87
  6 => int 97
array (size=6)
  0 => int 5
  1 => int 18
  2 => int 39
  3 => int 88
  4 => int 96
  5 => int 97
array (size=4)
  0 => int 1
  1 => int 40
  2 => int 56
  3 => int 93
array (size=7)
  0 => int 6
  1 => int 15
  2 => int 30
  3 => int 58
  4 => int 65
  5 => int 72
  6 => int 79
array (size=5)
  0 => int 5
  1 => int 10
  2 => int 43
  3 => int 62
  4 => int 88
array (size=5)
  0 => int 49
  1 => int 53
  2 => int 64
  3 => int 75
  4 => int 86
array (size=6)
  0 => int 8
  1 => int 37
  2 => int 55
  3 => int 66
  4 => int 74
  5 => int 82
array (size=7)
  0 => int 1
  1 => int 4
  2 => int 45
  3 => int 52
  4 => int 57
  5 => int 64
  6 => int 70
array (size=5)
  0 => int 2
  1 => int 12
  2 => int 17
  3 => int 74
  4 => int 94
array (size=5)
  0 => int 14
  1 => int 21
  2 => int 43
  3 => int 57
  4 => int 88
array (size=6)
  0 => int 5
  1 => int 17
  2 => int 78
  3 => int 85
  4 => int 93
  5 => int 99
array (size=7)
  0 => int 20
  1 => int 26
  2 => int 59
  3 => int 60
  4 => int 62
  5 => int 63
  6 => int 89
array (size=4)
  0 => int 6
  1 => int 49
  2 => int 84
  3 => int 85
array (size=5)
  0 => int 1
  1 => int 7
  2 => int 28
  3 => int 64
  4 => int 70
array (size=5)
  0 => int 5
  1 => int 19
  2 => int 48
  3 => int 58
  4 => int 85
array (size=3)
  0 => int 19
  1 => int 55
  2 => int 77
array (size=6)
  0 => int 15
  1 => int 16
  2 => int 36
  3 => int 79
  4 => int 83
  5 => int 98
array (size=3)
  0 => int 10
  1 => int 36
  2 => int 49
array (size=7)
  0 => int 2
  1 => int 3
  2 => int 6
  3 => int 13
  4 => int 14
  5 => int 52
  6 => int 66
array (size=5)
  0 => int 16
  1 => int 36
  2 => int 70
  3 => int 71
  4 => int 95
array (size=7)
  0 => int 1
  1 => int 16
  2 => int 21
  3 => int 61
  4 => int 78
  5 => int 91
  6 => int 97
array (size=7)
  0 => int 29
  1 => int 43
  2 => int 62
  3 => int 67
  4 => int 74
  5 => int 90
  6 => int 99
array (size=7)
  0 => int 12
  1 => int 30
  2 => int 37
  3 => int 46
  4 => int 62
  5 => int 66
  6 => int 99
array (size=7)
  0 => int 6
  1 => int 12
  2 => int 40
  3 => int 41
  4 => int 82
  5 => int 95
  6 => int 100
array (size=4)
  0 => int 37
  1 => int 89
  2 => int 98
  3 => int 100
array (size=5)
  0 => int 19
  1 => int 25
  2 => int 26
  3 => int 56
  4 => int 59
array (size=5)
  0 => int 20
  1 => int 27
  2 => int 34
  3 => int 84
  4 => int 93
array (size=7)
  0 => int 1
  1 => int 24
  2 => int 36
  3 => int 44
  4 => int 68
  5 => int 70
  6 => int 81
array (size=4)
  0 => int 46
  1 => int 52
  2 => int 60
  3 => int 84
array (size=6)
  0 => int 1
  1 => int 46
  2 => int 82
  3 => int 86
  4 => int 89
  5 => int 99
array (size=5)
  0 => int 39
  1 => int 51
  2 => int 53
  3 => int 66
  4 => int 91
array (size=4)
  0 => int 22
  1 => int 46
  2 => int 75
  3 => int 96
array (size=3)
  0 => int 72
  1 => int 85
  2 => int 91
array (size=3)
  0 => int 17
  1 => int 82
  2 => int 97
array (size=4)
  0 => int 2
  1 => int 8
  2 => int 43
  3 => int 83
array (size=5)
  0 => int 3
  1 => int 8
  2 => int 14
  3 => int 68
  4 => int 78
array (size=7)
  0 => int 3
  1 => int 5
  2 => int 12
  3 => int 63
  4 => int 72
  5 => int 89
  6 => int 94
array (size=5)
  0 => int 14
  1 => int 45
  2 => int 70
  3 => int 73
  4 => int 95
array (size=5)
  0 => int 27
  1 => int 33
  2 => int 38
  3 => int 75
  4 => int 97
array (size=7)
  0 => int 7
  1 => int 19
  2 => int 61
  3 => int 66
  4 => int 76
  5 => int 79
  6 => int 80
array (size=7)
  0 => int 15
  1 => int 22
  2 => int 51
  3 => int 73
  4 => int 84
  5 => int 87
  6 => int 89
array (size=6)
  0 => int 13
  1 => int 46
  2 => int 64
  3 => int 65
  4 => int 85
  5 => int 97
array (size=4)
  0 => int 15
  1 => int 31
  2 => int 56
  3 => int 93
array (size=5)
  0 => int 11
  1 => int 32
  2 => int 69
  3 => int 88
  4 => int 89
array (size=3)
  0 => int 18
  1 => int 81
  2 => int 96
array (size=4)
  0 => int 52
  1 => int 56
  2 => int 58
  3 => int 98
array (size=5)
  0 => int 4
  1 => int 25
  2 => int 30
  3 => int 84
  4 => int 88
array (size=6)
  0 => int 15
  1 => int 40
  2 => int 59
  3 => int 60
  4 => int 68
  5 => int 71
array (size=6)
  0 => int 53
  1 => int 65
  2 => int 67
  3 => int 77
  4 => int 83
  5 => int 84
array (size=4)
  0 => int 43
  1 => int 48
  2 => int 70
  3 => int 99
array (size=5)
  0 => int 22
  1 => int 47
  2 => int 48
  3 => int 68
  4 => int 74
array (size=6)
  0 => int 2
  1 => int 5
  2 => int 31
  3 => int 72
  4 => int 76
  5 => int 86
array (size=3)
  0 => int 52
  1 => int 57
  2 => int 71
array (size=6)
  0 => int 25
  1 => int 28
  2 => int 62
  3 => int 68
  4 => int 74
  5 => int 80
array (size=7)
  0 => int 35
  1 => int 40
  2 => int 51
  3 => int 61
  4 => int 63
  5 => int 66
  6 => int 67
array (size=3)
  0 => int 79
  1 => int 96
  2 => int 100
Array
(
    [1] => Array
        (
            [1] => 57,62,75
        )

    [2] => Array
        (
            [2] => 25,40,59,70,71
        )

    [3] => Array
        (
            [3] => 24,34,48,52,55,71,94
        )

    [4] => Array
        (
            [4] => 10,14,19,57,78,82,99
        )

    [5] => Array
        (
            [5] => 3,4,61,84
        )

    [6] => Array
        (
            [6] => 9,15,17,30,71,94
        )

    [7] => Array
        (
            [7] => 4,7,17,33,34,70,86
        )

    [8] => Array
        (
            [8] => 1,28,73,84
        )

    [9] => Array
        (
            [9] => 53,61,73,77,100
        )

    [10] => Array
        (
            [10] => 11,15,20,38,81,89
        )

    [11] => Array
        (
            [11] => 52,56,73,78,86,99
        )

    [12] => Array
        (
            [12] => 37,46,68,75,81
        )

    [13] => Array
        (
            [13] => 26,49,91,92
        )

    [14] => Array
        (
            [14] => 9,21,55,80,89,90,97
        )

    [15] => Array
        (
            [15] => 6,10,27,40,48,53
        )

    [16] => Array
        (
            [16] => 4,8,58,65,83,97,98
        )

    [17] => Array
        (
            [17] => 9,36,37,40,62,89
        )

    [18] => Array
        (
            [18] => 20,32,76
        )

    [19] => Array
        (
            [19] => 25,39,43,54
        )

    [20] => Array
        (
            [20] => 8,46,47,58,96
        )

    [21] => Array
        (
            [21] => 29,36,58,68,73
        )

    [22] => Array
        (
            [22] => 3,6,11,16,21,53
        )

    [23] => Array
        (
            [23] => 9,10,80,91,93,96,97
        )

    [24] => Array
        (
            [24] => 1,29,46
        )

    [25] => Array
        (
            [25] => 11,15,20,35,58,99
        )

    [26] => Array
        (
            [26] => 69,72,83
        )

    [27] => Array
        (
            [27] => 37,44,49,64,66
        )

    [28] => Array
        (
            [28] => 15,43,47,94
        )

    [29] => Array
        (
            [29] => 7,71,82
        )

    [30] => Array
        (
            [30] => 4,69,74
        )

    [31] => Array
        (
            [31] => 16,23,42,44,60,83
        )

    [32] => Array
        (
            [32] => 6,17,31,41,60,65,87
        )

    [33] => Array
        (
            [33] => 12,28,34,41,46,53,62
        )

    [34] => Array
        (
            [34] => 3,15,100
        )

    [35] => Array
        (
            [35] => 37,54,89
        )

    [36] => Array
        (
            [36] => 14,41,51,59
        )

    [37] => Array
        (
            [37] => 19,21,40,48,53,73,83
        )

    [38] => Array
        (
            [38] => 15,37,56,60,65,97
        )

    [39] => Array
        (
            [39] => 23,40,59,92,97
        )

    [40] => Array
        (
            [40] => 24,51,68,80
        )

    [41] => Array
        (
            [41] => 11,52,81
        )

    [42] => Array
        (
            [42] => 16,18,33,40,44
        )

    [43] => Array
        (
            [43] => 28,31,41,61,72,87
        )

    [44] => Array
        (
            [44] => 2,5,68
        )

    [45] => Array
        (
            [45] => 31,32,33,72,78,87,97
        )

    [46] => Array
        (
            [46] => 5,18,39,88,96,97
        )

    [47] => Array
        (
            [47] => 1,40,56,93
        )

    [48] => Array
        (
            [48] => 6,15,30,58,65,72,79
        )

    [49] => Array
        (
            [49] => 5,10,43,62,88
        )

    [50] => Array
        (
            [50] => 49,53,64,75,86
        )

    [51] => Array
        (
            [51] => 8,37,55,66,74,82
        )

    [52] => Array
        (
            [52] => 1,4,45,52,57,64,70
        )

    [53] => Array
        (
            [53] => 2,12,17,74,94
        )

    [54] => Array
        (
            [54] => 14,21,43,57,88
        )

    [55] => Array
        (
            [55] => 5,17,78,85,93,99
        )

    [56] => Array
        (
            [56] => 20,26,59,60,62,63,89
        )

    [57] => Array
        (
            [57] => 6,49,84,85
        )

    [58] => Array
        (
            [58] => 1,7,28,64,70
        )

    [59] => Array
        (
            [59] => 5,19,48,58,85
        )

    [60] => Array
        (
            [60] => 19,55,77
        )

    [61] => Array
        (
            [61] => 15,16,36,79,83,98
        )

    [62] => Array
        (
            [62] => 10,36,49
        )

    [63] => Array
        (
            [63] => 2,3,6,13,14,52,66
        )

    [64] => Array
        (
            [64] => 16,36,70,71,95
        )

    [65] => Array
        (
            [65] => 1,16,21,61,78,91,97
        )

    [66] => Array
        (
            [66] => 29,43,62,67,74,90,99
        )

    [67] => Array
        (
            [67] => 12,30,37,46,62,66,99
        )

    [68] => Array
        (
            [68] => 6,12,40,41,82,95,100
        )

    [69] => Array
        (
            [69] => 37,89,98,100
        )

    [70] => Array
        (
            [70] => 19,25,26,56,59
        )

    [71] => Array
        (
            [71] => 20,27,34,84,93
        )

    [72] => Array
        (
            [72] => 1,24,36,44,68,70,81
        )

    [73] => Array
        (
            [73] => 46,52,60,84
        )

    [74] => Array
        (
            [74] => 1,46,82,86,89,99
        )

    [75] => Array
        (
            [75] => 39,51,53,66,91
        )

    [76] => Array
        (
            [76] => 22,46,75,96
        )

    [77] => Array
        (
            [77] => 72,85,91
        )

    [78] => Array
        (
            [78] => 17,82,97
        )

    [79] => Array
        (
            [79] => 2,8,43,83
        )

    [80] => Array
        (
            [80] => 3,8,14,68,78
        )

    [81] => Array
        (
            [81] => 3,5,12,63,72,89,94
        )

    [82] => Array
        (
            [82] => 14,45,70,73,95
        )

    [83] => Array
        (
            [83] => 27,33,38,75,97
        )

    [84] => Array
        (
            [84] => 7,19,61,66,76,79,80
        )

    [85] => Array
        (
            [85] => 15,22,51,73,84,87,89
        )

    [86] => Array
        (
            [86] => 13,46,64,65,85,97
        )

    [87] => Array
        (
            [87] => 15,31,56,93
        )

    [88] => Array
        (
            [88] => 11,32,69,88,89
        )

    [89] => Array
        (
            [89] => 18,81,96
        )

    [90] => Array
        (
            [90] => 52,56,58,98
        )

    [91] => Array
        (
            [91] => 4,25,30,84,88
        )

    [92] => Array
        (
            [92] => 15,40,59,60,68,71
        )

    [93] => Array
        (
            [93] => 53,65,67,77,83,84
        )

    [94] => Array
        (
            [94] => 43,48,70,99
        )

    [95] => Array
        (
            [95] => 22,47,48,68,74
        )

    [96] => Array
        (
            [96] => 2,5,31,72,76,86
        )

    [97] => Array
        (
            [97] => 52,57,71
        )

    [98] => Array
        (
            [98] => 25,28,62,68,74,80
        )

    [99] => Array
        (
            [99] => 35,40,51,61,63,66,67
        )

    [100] => Array
        (
            [100] => 79,96,100
        )

)

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