3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } var_dump(random_str(32)); var_dump(random_str(8, 'abcdefghijklmnopqrstuvwxyz'));
based on KKlc3
Output for 7.2.6
string(32) "BH0AEWGY269HyPKH4rLFL9vd3Q4xaH90" string(8) "iljtiiqc"
Output for 7.2.0
string(32) "KG0xATfo1Qlpk4EOnsROEukkYl1okvs7" string(8) "bfgnhqjb"
Output for 7.1.10
string(32) "mlDbPar4SuB61t2EuJEBgma9T4MTRTBn" string(8) "nwvktibo"
Output for 7.1.7
string(32) "dnCig6DjLLJ5qyzAdtRxceMxVnebksvF" string(8) "skbijgdf"
Output for 7.1.6
string(32) "Bfqs6QLeJYxYLN0P6veCrBzZ4fWJAb3a" string(8) "coedvsax"
Output for 7.1.5
string(32) "kKz9UjvzGHhrWjDtejUotuebviYtBSkQ" string(8) "skkykdlw"
Output for 7.1.4
string(32) "fvMLOMCsIYXqbPINY1Qk63XJG55CDIrX" string(8) "qryfkohx"
Output for 7.1.3
string(32) "H2PKJvdMgvQmrhDFCWZzoDT9wCu7Tz4r" string(8) "yvisjdng"
Output for 7.1.2
string(32) "Y08iL9LnnYl4IJ0rGkoD3cIfcwzOv0Gx" string(8) "qanpkwvr"
Output for 7.1.1
string(32) "RhlRnFBYhzYyqXdO3IHU3mQjkeTYIswr" string(8) "mufaqmzc"
Output for 7.1.0
string(32) "ZCpbdkQcEX8sUSROViERx0KIwND4w7T6" string(8) "uycqhnto"
Output for 7.0.20
string(32) "cnKOeJvQbjq8N8D0OiEgEDisntQriGwu" string(8) "vrhpclum"
Output for 7.0.19
string(32) "l2jbqDWO6XQuv4AHcnirMBYmqwHpsSXA" string(8) "iagscyyi"
Output for 7.0.18
string(32) "H7i8zIrdAW4JmcPJuYDrnMLDAPtgybIS" string(8) "kodzlven"
Output for 7.0.17
string(32) "ZygkfKx2qcOTNvb82tzSEhj4y5vgNpvD" string(8) "orulgqnp"
Output for 7.0.16
string(32) "zonq7v4EIAJsFigx0ssFkGD3XYIDOfUd" string(8) "kzualizp"
Output for 7.0.15
string(32) "0giSEZvsWfh0JuKQwoWl28fr0iSNsZWm" string(8) "yxlynxim"
Output for 7.0.14
string(32) "CSxf8XKr5QzYfKbMjuZkcweNANMMBU5K" string(8) "oqwwpery"
Output for 7.0.13
string(32) "x7IRRhf6MgQOvKWFgZXmVfdLGCQcTX8I" string(8) "fmnlcnnm"
Output for 7.0.12
string(32) "XILCf0BFhY3Wi8dKYcR9CPBEU8b9WIKj" string(8) "tbcmwlbj"
Output for 7.0.11
string(32) "SOOw8f7jy7LAO3Lfimic8SfPXu0G4Z27" string(8) "lxnbmzlu"
Output for 7.0.10
string(32) "kf32bTlxX8vxyajgShQu1gCiaXieymkC" string(8) "ognxjxiw"
Output for 7.0.9
string(32) "ZPWPqhlV1NBvGLdDEFuqipYNGiUzisP5" string(8) "fhliclqu"
Output for 7.0.8
string(32) "2XOsgogafMUGtOOfb5cqnaCiwT0m5aEB" string(8) "qjabcbew"
Output for 7.0.7
string(32) "CuOm70PZNHi6hOxCRzBAgh7FfIuLc9Ke" string(8) "upiczscb"
Output for 7.0.6
string(32) "P8lCkckAlOZk3jtGenbSqSuIgQNtEnZx" string(8) "sisqgcqb"
Output for 7.0.5
string(32) "wnXTqTpGreOZPPq06j0AePSMURZo1DSz" string(8) "ivozxezl"
Output for 7.0.4
string(32) "8swNX2l1UpiQAZBoXAJV7OVBOkZQGDwE" string(8) "bayenkti"
Output for 7.0.3
string(32) "JrIjbktSlRWtqaUJRE0jS4Sp7XcRpxe7" string(8) "nzwdmzzv"
Output for 7.0.2
string(32) "ekqi1Un5WONoW3Kee3lhzG0hNGDbBAfO" string(8) "wipfrhzl"
Output for 7.0.1
string(32) "ZVfDPYrTnt4OV6qhd0aGsI2uwWKxbVI8" string(8) "vuzkfgft"
Output for 7.0.0
string(32) "Gn4Bz7aMduCPIqB5oVoRut6V9FFiDRfi" string(8) "mwiowfbs"
Output for hhvm-3.15.4
string(32) "BXoayOezc5y662OyiiPiF1bm5l88XrAC" string(8) "tscqzjjr"
Output for 5.6.0 - 5.6.30
Fatal error: Call to undefined function random_int() in /in/XaTLE on line 9
Process exited with code 255.