3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * For PHP 7, random_int is a PHP core function * For PHP 5.x, depends on https://github.com/paragonie/random_compat * * @param int $length How many characters do we want? * @param string $keyspace A string of all possible characters * to select from * @return string */ function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } var_dump(random_str(32)); var_dump(random_str(8, 'abcdefghijklmnopqrstuvwxyz'));
Output for 7.3.0rc6
string(32) "akgg7T5moymN2RLlsgBHNBDE8GqjFT5W" string(8) "dikweghf"
Output for 7.3.0rc5
string(32) "wKaNSgBL3k6kXShPYu4nMIcS6QBolKR3" string(8) "qyfnlklr"
Output for 7.3.0rc4
string(32) "onlCndXIfA30xQ8VA9aPvmiU1ZP2xSYx" string(8) "dqcpijzk"
Output for 7.3.0rc3
string(32) "dKilt4sQMJZ3cu9s1oqZwprWPXQ9jgYl" string(8) "bfvshfol"
Output for 7.3.0rc2
string(32) "QnRSdtpjMXBHGFEN3uusOFAXZGsCL9Hr" string(8) "jwbxwisg"
Output for 7.3.0rc1
string(32) "oS31v2AZseyamQFJkVIvy4rUCNxHuTR1" string(8) "shwciqut"
Output for 7.3.0beta3
string(32) "yI8oh1JIvXecayn5WZEDAKWzIwyGqHzZ" string(8) "qatcwopz"
Output for 7.3.0beta2
string(32) "YO0lZR3GW1xKOdqnbIhy13jOgXGKgJqD" string(8) "xwgxtpkr"
Output for 7.3.0beta1
string(32) "KB4O2JrLaWJe4C4xcB4Qr43DXLYPX5T3" string(8) "ymddotew"
Output for 7.3.0alpha4
string(32) "pWabVsLLZXiacFQbwfJKeVbXWHLPMnMS" string(8) "vjnuvbou"
Output for 7.3.0alpha3
string(32) "S594ee6QNSoAFsywO3Ym7LnNmbnFuLRu" string(8) "soimczzl"
Output for 7.3.0alpha2
string(32) "8HPDHkkL6k94ZRnopFVnOEhNT7EsekfR" string(8) "auiuxjie"
Output for 7.3.0alpha1
string(32) "6wSnbM7jbPRwuYyZVUX4AVuOTxlvOsdY" string(8) "wfzjumkw"
Output for 7.3.0
string(32) "fVgxHunGnIzr8zxMxkEZzZWw6yktUPzM" string(8) "jvbooziy"
Output for 7.2.13
string(32) "i4um8FX5xg5JoBWWGG7P8JaeglQUGhHJ" string(8) "dpmjuela"
Output for 7.2.12
string(32) "ZJHUFnA0Ou8NGTtntMyzb4fsVxDwl1sj" string(8) "eqrbmvmw"
Output for 7.2.11
string(32) "T38iWy1whizT74rtaE5gLgccYKhZ8dCi" string(8) "ebtmosuf"
Output for 7.2.10
string(32) "aP3W61S4Ks4KoFfR807Gt6UxALHBNOQG" string(8) "tnssnoes"
Output for 7.2.9
string(32) "vCH2iGzxdJoCDxar9Sgtc6ATPIMhAmgl" string(8) "hoohhspx"
Output for 7.2.8
string(32) "Oi42nMsjm1gqFzjHWJVCam1Y6o3wNgaQ" string(8) "wbfdkgmm"
Output for 7.2.7
string(32) "g327EJ26FAxZchYXWPDXkWCzJHh1k0Uc" string(8) "cmqkqzjk"
Output for 7.2.6
string(32) "bOmzhn1isepJmkGAr8oenywqwhMOnaM7" string(8) "jpuisnrm"
Output for 7.2.5
string(32) "PLVxlIQ5WYdqjR9DgIDCcoReqVq76u5R" string(8) "ezkuklul"
Output for 7.2.4
string(32) "FgRJI7Gtf0oH4OBRWu7jrTSNxJtDPnFK" string(8) "rqmpnriv"
Output for 7.2.3
string(32) "b1CCoq2gncsGKQc5SyOsFClfpaTB1c5K" string(8) "dbajwjpv"
Output for 7.2.2
string(32) "7fy9RY2f12cnvylDxlwoFFh5SwHS53z1" string(8) "jtnbfozf"
Output for 7.2.1
string(32) "KpzOg5wSZjJF8E4rXtM1dhWVxfs4Wggi" string(8) "losfagpc"
Output for 7.2.0
string(32) "hLEnRU0HUmCFUtcvex3SY97kisyqasz5" string(8) "chwuazef"
Output for 7.1.25
string(32) "05ljeq2QIK0omMSJBxF1aYI2lt0vRmFb" string(8) "dobesfwc"
Output for 7.1.24
string(32) "zrqUNhbQ3kB7OZ0981ZBbHaNGTGCjW0z" string(8) "ssbkronf"
Output for 7.1.23
string(32) "gdFm4oIKLgQxr0R5Yl7O6NG9FQj1PsZf" string(8) "swcxklsi"
Output for 7.1.22
string(32) "Kdg53gngDkDqw9jz6Xy2k9JdcBww3KFI" string(8) "fmrxuvgj"
Output for 7.1.21
string(32) "lTfMFndryrc54xbZpbYVhsNz4BJmT3RX" string(8) "vztwoinw"
Output for 7.1.20
string(32) "ym5NU18xBTdSwOwzLTFoBF1hMCkFSUa3" string(8) "ejhwzyhy"
Output for 7.1.19
string(32) "woNzcrcCTa8aJNypyii1LGnCU4r5MdpD" string(8) "qrhzihql"
Output for 7.1.18
string(32) "183u2uCicbfO2I4I2lv6b6oZHJXyoaub" string(8) "nqeoijfg"
Output for 7.1.17
string(32) "s9QVlaOyN7a9y4PIhmmnxD26ugh5LCix" string(8) "kskutscq"
Output for 7.1.16
string(32) "uu9ijdGkshh7itkCZYNi4qUZtbhxelHh" string(8) "bsekbxfk"
Output for 7.1.15
string(32) "k4czzO2ENbT690XazDaTOrwUVek6owEN" string(8) "oalmramz"
Output for 7.1.14
string(32) "gmEslMI5W2VEdbjgzoOMsI8ZvCgLOlcq" string(8) "vrpfgmxk"
Output for 7.1.13
string(32) "9D2WvgBQigenyV1AAmtDtqbhvsZwoWJa" string(8) "yylwygba"
Output for 7.1.12
string(32) "tZT6SgDKtqehRkYQhc0mXMS6GcGA5mu3" string(8) "iokulksk"
Output for 7.1.11
string(32) "SwQfcIDf0egGtpz29GacYnx15QrgmNVe" string(8) "crqgqlzo"
Output for 7.1.10
string(32) "QqmLxFwpADhg4J3SBjhVXYdBTA3GDmxo" string(8) "qlonmwxb"
Output for 7.1.9
string(32) "JwgdzAoojyZsqo7RceuaVk6ympVIUXgW" string(8) "zcttbwvy"
Output for 7.1.8
string(32) "Mhee9PXr89BVj3acpFLDVesE6AQ0AUXW" string(8) "bgvhxtvw"
Output for 7.1.7
string(32) "9rl0zCbb3qruJ8BYdQb74DIBqQ7LAQI5" string(8) "zrdqwujj"
Output for 7.1.6
string(32) "e3mSa0jVJUH9WkhcS3IaEtMqM911jPg5" string(8) "wpldujqz"
Output for 7.1.5
string(32) "mDBVy8kVWhp1eIj5rFyuX3KRQTAwkq6d" string(8) "msafxpcq"
Output for 7.1.4
string(32) "J1WwsUtpiFd5LPE0jERZrRyPHcBukDKT" string(8) "cgecqctn"
Output for 7.1.3
string(32) "TaZLWX8nmxFXcBxfH7VCGPKcV3F0YhFe" string(8) "jumldcpq"
Output for 7.1.2
string(32) "eyhuPxePTpq10MfewKNylLHVry78OsVE" string(8) "xwwjhbha"
Output for 7.1.1
string(32) "qxknxXJVb7Yfc6qxM3HmyZcfKWWLnXtA" string(8) "whgsaknj"
Output for 7.1.0
string(32) "7qVPRRVdlefoCYuvND8gy0jTybU7I3pN" string(8) "gohjaxqq"
Output for 7.0.33
string(32) "gczdcwdpt0Z8RMaUJEJoKW8RkeqFkcUG" string(8) "jgpvxduu"
Output for 7.0.32
string(32) "0foXCATUbYdKXLfQ8emnIhR3vLN5ZqDY" string(8) "zwhsqwjb"
Output for 7.0.31
string(32) "HYJsy1rl40w6rsZSEs9quI3qxY6wKOj3" string(8) "pcxjeifg"
Output for 7.0.30
string(32) "g9UDHixPtyW7icmtN0vEJhvo1cR3Rip8" string(8) "rvbpeoff"
Output for 7.0.29
string(32) "HIVicQpAQVTC8qPrbhHsspuv2MLNBQda" string(8) "skhqaern"
Output for 7.0.28
string(32) "pQE0LzWkmGgThaN66Myv0HJZ3AxURM4d" string(8) "zsqklpro"
Output for 7.0.27
string(32) "MMrbFXKhQi3dP9If69W9H2bQHCg5u7WB" string(8) "iwzldlyf"
Output for 7.0.26
string(32) "YTcSdhLQ265lhjPRYXQvZPc09Bevkm8W" string(8) "szkaagfw"
Output for 7.0.25
string(32) "N1gqvnmS3j9GYX2JDRymsJLtBdYPNHSQ" string(8) "famdglev"
Output for 7.0.24
string(32) "IGjQOXIvDsZKftCmvaBk3qThABPazDJ3" string(8) "kkndtuof"
Output for 7.0.23
string(32) "G1MJE4Dc9YoDLjt9HLtchj7lybGOT0CM" string(8) "baewtyna"
Output for 7.0.22
string(32) "uIrWHfkQHzcPoHxDifJNH8rfXFwqX9av" string(8) "zojgaexc"
Output for 7.0.21
string(32) "Ht5aBAhnT6bhVcSyfaJK2dRC6qwoG0lu" string(8) "ggmvfgip"
Output for 7.0.20
string(32) "wRaqau9NdPZEUswNiiGiI3NvKiJY230r" string(8) "wersvhtf"
Output for 7.0.19
string(32) "xXxH0sTB40cp8krvAn2XbCaDUWaiUkpW" string(8) "hihurhfz"
Output for 7.0.18
string(32) "xI8gJPrmCiVftDOjIMPSWEWRloDhNNH7" string(8) "zsylqprl"
Output for 7.0.17
string(32) "O9wgYxW0079f2IyLFdFmKBjbAq1t0zFw" string(8) "lsuktamn"
Output for 7.0.16
string(32) "fapTjWbCKgI5oinc72QAGY0aqPspq0my" string(8) "ikkcrhrf"
Output for 7.0.15
string(32) "iB2YCXOtWvwaNdNvyjftcYx5ZdcKyqsz" string(8) "bfdqvfhg"
Output for 7.0.14
string(32) "rOjDDjzEZDmjdUDBhu9Dbbt6YZQkTXK4" string(8) "xpzwvtcv"
Output for 7.0.13
string(32) "o04iEOTei6RmPiQGlTDkMislNXTRqWtd" string(8) "pcblpdcv"
Output for 7.0.12
string(32) "p0DRef1cXJJf8LLCE4RujTCfx3QqArok" string(8) "liylqtha"
Output for 7.0.11
string(32) "9H39rnr1n28Idb52vbuZndHhj9jJ401h" string(8) "ylfnxjwv"
Output for 7.0.10
string(32) "jA1xKyRaeIby5Nrk5ZcXH5iAoTxg79TX" string(8) "jfgkqmel"
Output for 7.0.9
string(32) "o1Cq32RDAhMAn3Iz2LABlY3CHPepQQAf" string(8) "xfnonsrh"
Output for 7.0.8
string(32) "x0qhLNQi1Otvuh6kuiygdtJvZIaIc9RB" string(8) "xsmbvwzm"
Output for 7.0.7
string(32) "urXmKFgm3uZgrzwhjdbaIbkD4PYgZGIQ" string(8) "jsumwinv"
Output for 7.0.6
string(32) "J6Qta8r3ZM4TvCHTSTqCpCJ2m7UtuwXu" string(8) "dfzsxlbr"
Output for 7.0.5
string(32) "ZmvWMGhJkzNvr7iCCpCXRX8ueriqlCeQ" string(8) "pikjqpfo"
Output for 7.0.4
string(32) "XsCutVUlbW27XHAQELNxqxIgWLyMbEqM" string(8) "lmthqqog"
Output for 7.0.3
string(32) "e74pqNMZVQgyPlhgRhDIec8r2954haUr" string(8) "rvhxmlih"
Output for 7.0.2
string(32) "KL6SURDlG4XxVBPl7fJtboozJh4fYCVS" string(8) "vlqifowd"
Output for 7.0.1
string(32) "Roir0Vm5JaIgm7zeRsaQBdlaqRsVkjXM" string(8) "adeahozp"
Output for 7.0.0
string(32) "oScwQb1hn1f2o7z83rgNgAdwDHhaEXOx" string(8) "dqhnbubm"
Output for hhvm-3.22.0
string(32) "hbwjUSr5QXybNN49BO20T5VAIxgVtUtZ" string(8) "ndyrebcs"
Output for hhvm-3.21.3
string(32) "fQ1QHRyV9gMZ0PKgiraEYsw57yl2YVqV" string(8) "zpbmbdci"
Output for hhvm-3.21.0
string(32) "ciDbEUR5Puc0qjjQg9DC4UQqa2q9hL4m" string(8) "orpkhooy"
Output for hhvm-3.20.2
string(32) "8uXyFCLUHLUWph8zfCGGnCSKwjHX4Jc8" string(8) "ttjuwbrq"
Output for hhvm-3.19.2
string(32) "NpbARmoR7m3NVSW7epFjJKxs0eT99dcF" string(8) "iipfsfxk"
Output for hhvm-3.18.5
string(32) "pJog8SoIQmV7ybkvVXMnAVtJnfnTL6mX" string(8) "ziqrceny"
Output for hhvm-3.18.4
string(32) "ot7LGJfADlJC2G8sICCCfwaMbmrN9gYV" string(8) "undjmrlw"
Output for hhvm-3.17.3
string(32) "WG8OsGzG1VkzankB7MuykXAIOUetBGKh" string(8) "pmyblmyb"
Output for hhvm-3.15.4
string(32) "ATA3Nul7vPA3in6hrJfJd3mALUM6VQt3" string(8) "hugzpcdq"
Output for hhvm-3.13.2
string(32) "fICYv2bhPz2EXfCAr1d19sSG0VPkmc6q" string(8) "bvzzngmg"
Output for hhvm-3.12.14
string(32) "12fkefaPBfzL2C0jQsZjyrt7x1VjJBYB" string(8) "vospvzns"
Output for hhvm-3.11.1
string(32) "7PDtsVqY0jdANVw3JijFNBrRzzxtKzw2" string(8) "ibcgiloa"
Output for 5.4.0 - 5.6.38, hhvm-3.10.1
Fatal error: Call to undefined function random_int() in /in/b4PST on line 20
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/b4PST on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/b4PST on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/b4PST on line 17
Process exited with code 255.