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 |
<?php function getRandomIdx($all) { $idxMax = count($all) - 1; $idxRandom = random_int(0, $idxMax); return $idxRandom; } function getArr() { $a = []; for ($i = 0; $i < 47; $i++) { $a[] = ''; } return $a; } $times = 10000; $a = []; for ($i = 0; $i < $times; $i++) { $all = getArr(); $idx = getRandomIdx($all); if (isset($a[$idx])) { $a[$idx]++; } else { $a[$idx] = 1; } } ksort($a); print_r($a); |
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 |
Array ( [0] => 203 [1] => 204 [2] => 225 [3] => 226 [4] => 189 [5] => 200 [6] => 219 [7] => 224 [8] => 207 [9] => 249 [10] => 195 [11] => 204 [12] => 223 [13] => 210 [14] => 210 [15] => 224 [16] => 224 [17] => 202 [18] => 203 [19] => 212 [20] => 222 [21] => 214 [22] => 207 [23] => 188 [24] => 221 [25] => 199 [26] => 249 [27] => 170 [28] => 193 [29] => 223 [30] => 210 [31] => 217 [32] => 206 [33] => 214 [34] => 232 [35] => 201 [36] => 200 [37] => 198 [38] => 237 [39] => 220 [40] => 229 [41] => 219 [42] => 212 [43] => 213 [44] => 210 [45] => 237 [46] => 206 ) |