1--TEST-- 2Random: Randomizer: Nul engines are correctly handled 3--FILE-- 4<?php 5 6use Random\Engine; 7use Random\Randomizer; 8 9final class NulEngine implements Engine 10{ 11 public function generate(): string 12 { 13 return str_repeat("\x00", PHP_INT_SIZE); 14 } 15} 16 17function randomizer(): Randomizer 18{ 19 return new Randomizer(new NulEngine()); 20} 21 22try { 23 var_dump(randomizer()->getInt(0, 1234)); 24} catch (Random\BrokenRandomEngineError $e) { 25 echo $e->getMessage(), PHP_EOL; 26} 27 28try { 29 var_dump(randomizer()->nextInt()); 30} catch (Random\BrokenRandomEngineError $e) { 31 echo $e->getMessage(), PHP_EOL; 32} 33 34try { 35 var_dump(bin2hex(randomizer()->getBytes(1))); 36} catch (Random\BrokenRandomEngineError $e) { 37 echo $e->getMessage(), PHP_EOL; 38} 39 40try { 41 var_dump(randomizer()->shuffleArray(range(1, 123))); 42} catch (Random\BrokenRandomEngineError $e) { 43 echo $e->getMessage(), PHP_EOL; 44} 45 46try { 47 var_dump(randomizer()->pickArrayKeys(range(1, 123), 1)); 48} catch (Random\BrokenRandomEngineError $e) { 49 echo $e->getMessage(), PHP_EOL; 50} 51 52try { 53 var_dump(randomizer()->pickArrayKeys(range(1, 123), 10)); 54} catch (Random\BrokenRandomEngineError $e) { 55 echo $e->getMessage(), PHP_EOL; 56} 57 58try { 59 var_dump(randomizer()->shuffleBytes('foobar')); 60} catch (Random\BrokenRandomEngineError $e) { 61 echo $e->getMessage(), PHP_EOL; 62} 63 64?> 65--EXPECTF-- 66int(0) 67int(0) 68string(2) "00" 69array(123) { 70 [0]=> 71 int(2) 72 [1]=> 73 int(3) 74 [2]=> 75 int(4) 76 [3]=> 77 int(5) 78 [4]=> 79 int(6) 80 [5]=> 81 int(7) 82 [6]=> 83 int(8) 84 [7]=> 85 int(9) 86 [8]=> 87 int(10) 88 [9]=> 89 int(11) 90 [10]=> 91 int(12) 92 [11]=> 93 int(13) 94 [12]=> 95 int(14) 96 [13]=> 97 int(15) 98 [14]=> 99 int(16) 100 [15]=> 101 int(17) 102 [16]=> 103 int(18) 104 [17]=> 105 int(19) 106 [18]=> 107 int(20) 108 [19]=> 109 int(21) 110 [20]=> 111 int(22) 112 [21]=> 113 int(23) 114 [22]=> 115 int(24) 116 [23]=> 117 int(25) 118 [24]=> 119 int(26) 120 [25]=> 121 int(27) 122 [26]=> 123 int(28) 124 [27]=> 125 int(29) 126 [28]=> 127 int(30) 128 [29]=> 129 int(31) 130 [30]=> 131 int(32) 132 [31]=> 133 int(33) 134 [32]=> 135 int(34) 136 [33]=> 137 int(35) 138 [34]=> 139 int(36) 140 [35]=> 141 int(37) 142 [36]=> 143 int(38) 144 [37]=> 145 int(39) 146 [38]=> 147 int(40) 148 [39]=> 149 int(41) 150 [40]=> 151 int(42) 152 [41]=> 153 int(43) 154 [42]=> 155 int(44) 156 [43]=> 157 int(45) 158 [44]=> 159 int(46) 160 [45]=> 161 int(47) 162 [46]=> 163 int(48) 164 [47]=> 165 int(49) 166 [48]=> 167 int(50) 168 [49]=> 169 int(51) 170 [50]=> 171 int(52) 172 [51]=> 173 int(53) 174 [52]=> 175 int(54) 176 [53]=> 177 int(55) 178 [54]=> 179 int(56) 180 [55]=> 181 int(57) 182 [56]=> 183 int(58) 184 [57]=> 185 int(59) 186 [58]=> 187 int(60) 188 [59]=> 189 int(61) 190 [60]=> 191 int(62) 192 [61]=> 193 int(63) 194 [62]=> 195 int(64) 196 [63]=> 197 int(65) 198 [64]=> 199 int(66) 200 [65]=> 201 int(67) 202 [66]=> 203 int(68) 204 [67]=> 205 int(69) 206 [68]=> 207 int(70) 208 [69]=> 209 int(71) 210 [70]=> 211 int(72) 212 [71]=> 213 int(73) 214 [72]=> 215 int(74) 216 [73]=> 217 int(75) 218 [74]=> 219 int(76) 220 [75]=> 221 int(77) 222 [76]=> 223 int(78) 224 [77]=> 225 int(79) 226 [78]=> 227 int(80) 228 [79]=> 229 int(81) 230 [80]=> 231 int(82) 232 [81]=> 233 int(83) 234 [82]=> 235 int(84) 236 [83]=> 237 int(85) 238 [84]=> 239 int(86) 240 [85]=> 241 int(87) 242 [86]=> 243 int(88) 244 [87]=> 245 int(89) 246 [88]=> 247 int(90) 248 [89]=> 249 int(91) 250 [90]=> 251 int(92) 252 [91]=> 253 int(93) 254 [92]=> 255 int(94) 256 [93]=> 257 int(95) 258 [94]=> 259 int(96) 260 [95]=> 261 int(97) 262 [96]=> 263 int(98) 264 [97]=> 265 int(99) 266 [98]=> 267 int(100) 268 [99]=> 269 int(101) 270 [100]=> 271 int(102) 272 [101]=> 273 int(103) 274 [102]=> 275 int(104) 276 [103]=> 277 int(105) 278 [104]=> 279 int(106) 280 [105]=> 281 int(107) 282 [106]=> 283 int(108) 284 [107]=> 285 int(109) 286 [108]=> 287 int(110) 288 [109]=> 289 int(111) 290 [110]=> 291 int(112) 292 [111]=> 293 int(113) 294 [112]=> 295 int(114) 296 [113]=> 297 int(115) 298 [114]=> 299 int(116) 300 [115]=> 301 int(117) 302 [116]=> 303 int(118) 304 [117]=> 305 int(119) 306 [118]=> 307 int(120) 308 [119]=> 309 int(121) 310 [120]=> 311 int(122) 312 [121]=> 313 int(123) 314 [122]=> 315 int(1) 316} 317array(1) { 318 [0]=> 319 int(0) 320} 321Failed to generate an acceptable random number in 50 attempts 322string(6) "oobarf" 323