3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // EXAMPLE USAGE $array = generate(); echo $array[0]; echo "<br />"; echo $array[1]; // FUNCTION function generate() { $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY"; //now we generate a new random ID number using the substrings of the digitList string above $id = NULL; $id .= substr($digilist, rand(9, 9), 1); //random number $id .= substr($digilist, rand(21, 21), 1); //then a letter $id .= substr($digilist, rand(14, 14), 1); //another letter $id .= substr($digilist, rand(2, 9), 1); //a number $id .= substr($digilist, rand(2, 2), 1); //and finally another number - simple :D //ok so now we need to generate an MD5 hash of our ID $hash = md5($id); //cycle through the hash 16 (length of key) times (in steps of 2 because each hex bytes is 2 digits long) $i = 0; $key = NULL; for ($i; $i < 32; $i+=2) { //here we convert the next hex value to an integer and perform a bitwise AND operation against '31' //31 is the highest substring value in our digit list. $nextdigit = hexdec(substr($hash, $i, 2)) & 31; //if 'i' is divisable by 8 (every 4 cycles) then we want to add "-" if ((($i % 8) == 0) && ($i > 0)) { $key .= "-".substr($digilist, $nextdigit, 1); } else { $key .= substr($digilist, $nextdigit, 1); } } $array = array($id, $key); //return return $array; } ?>
based on ejUEL
Output for 5.6.10 - 5.6.11, 5.6.19 - 5.6.20, 5.6.30, hhvm-3.15.4, 7.0.3, 7.0.6, 7.0.8 - 7.0.9, 7.1.4, 7.1.6, 7.2.6
9ME42<br />NLAR-62CV-00B4-NKVG
Output for 5.6.0, 5.6.25, 7.0.7, 7.0.10 - 7.0.11, 7.0.15, 7.0.18, 7.1.0, 7.2.0
9ME92<br />NG62-9Q0E-J844-323F
Output for 5.6.4, 5.6.14, 7.0.19, 7.1.10
9ME22<br />R8TG-BJYV-182T-BLF5
Output for 5.6.2, 5.6.22, 5.6.26, 5.6.28, 7.0.13, 7.1.2, 7.1.5, 7.1.7
9ME52<br />FMRK-9VTB-U4YX-7K52
Output for 5.6.12, 5.6.17, 5.6.21, 5.6.24, 5.6.29, 7.0.0, 7.0.5, 7.1.3
9ME82<br />EQGW-BAXK-1RHN-DXLP
Output for 5.6.1, 5.6.5, 5.6.7 - 5.6.8, 5.6.13, 7.0.14, 7.1.1
9ME62<br />R8M0-XCTG-EBMM-23QH
Output for 5.6.9, 5.6.27, 7.0.1 - 7.0.2, 7.0.12, 7.0.20
9ME32<br />KUVD-K1B0-FQYQ-4NUP
Output for 5.6.3, 5.6.6, 5.6.15 - 5.6.16, 5.6.18, 5.6.23, 7.0.4, 7.0.16 - 7.0.17
9ME72<br />4T22-EKLM-GC72-N73G