3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.1.4
string(32) "WKunrrxwvzXMqNEtNBP58VgGeIWl4Nek" string(8) "vwwrfgvy"
Output for 7.4.9
string(32) "CR0DiWkLYN337U8fTi1kbeVcGeiTLNGh" string(8) "xxehixds"
Output for 7.4.8
string(32) "XjHcp1DVJuxMk0TV2hgNOFMJONRJcMux" string(8) "krxcmpez"
Output for 7.4.7
string(32) "gaZqjZPPZYOBfOxBTLbW9EuRJUriGjlE" string(8) "mqjgllms"
Output for 7.4.6
string(32) "jRLeHj6dKBFINu2uWy9kMTmTsLMS73fJ" string(8) "ypxpbjkn"
Output for 7.4.5
string(32) "WHlficuCOEEgv4ox63aQi4GMA7cvjISU" string(8) "yubhebgo"
Output for 7.4.4
string(32) "SxsoHRXiFIepkDY1e0bk1BKhSd4skX4B" string(8) "dunpfhgt"
Output for 7.4.3
string(32) "5PUMCa0fHLDzx1wzLtOJSGskbfxMH1up" string(8) "aaloxbra"
Output for 7.4.2
string(32) "4J8OLfLxz6nVYcU2GZwD3rCw0HRrkkze" string(8) "pjhfmbly"
Output for 7.4.1
string(32) "hN8gOhiKP0HdXZTp8074n1fLawHG0nkA" string(8) "gcieippu"
Output for 7.4.0
string(32) "SUxcd70N06VLleBr9JMgpGTmAzLA47pt" string(8) "uptaqavc"
Output for 7.3.21
string(32) "WJ2s3Juhk3KujP16FnxUPSthX2OUBF7E" string(8) "tviszyee"
Output for 7.3.20
string(32) "y74mdOpZUDScvihUcWxWcxPmTJQn5JgI" string(8) "fxxtyoqb"
Output for 7.3.19
string(32) "ymyGngqu1O7ROWdZOEIDlT1xHTCvWmH9" string(8) "wrqtwybh"
Output for 7.3.18
string(32) "R9BeAtj2sQgGq8P4d4h5PEDTWoOqR5FB" string(8) "qkykrshr"
Output for 7.3.17
string(32) "uJmmbVTuRKRYIRtmbmYfcXijlr0MjNBG" string(8) "ifgvbbza"
Output for 7.3.16
string(32) "Dx9M0xacPwcB3H3r0MM5vQRheIDxhs1W" string(8) "gdahvund"
Output for 7.3.15
string(32) "SzOFxOyEcUsEwHD155FrqWl9b3dobmgP" string(8) "cygtuxgn"
Output for 7.3.14
string(32) "IRFPaslOdhZsJRTnRWUfZHLR2CLPfcro" string(8) "gwdlyage"
Output for 7.3.13
string(32) "VvbXnBgn5wMN3bWvQP1Z6gna4pAM5OcY" string(8) "izshvqoa"
Output for 7.3.12
string(32) "4Xevc2BkTl8V9J3NTsABRFWdGSDiyfuM" string(8) "ibksodcf"
Output for 7.3.11
string(32) "5VNuIoFaoWcpGShsdlMmm7JG9kPgiqLP" string(8) "rrccykbe"
Output for 7.3.10
string(32) "tCWg8GVMWpq9eJ9gpz90URpP4ffBG45t" string(8) "eydqvhkl"
Output for 7.3.9
string(32) "5q7pSFY9RuDz1fJkKGvmCcmOUV4Bu1CV" string(8) "ibbjimcf"
Output for 7.3.8
string(32) "7Qb47ky5O5P9Giave8TRE4RXhRqvtJSV" string(8) "cbpikaec"
Output for 7.3.7
string(32) "vZemJhmnH5KtlkAAvgqgEmO8Q72jO79Q" string(8) "vqcgsqhy"
Output for 7.3.6
string(32) "3xaf9Nggvma7RNvSlQYRgxw0N35k8EPR" string(8) "rdsrctbw"
Output for 7.3.5
string(32) "WUq5XGEZxBBEf6i1C47KL1QZILrpTKKU" string(8) "mjpngeec"
Output for 7.3.4
string(32) "X7a180UHjzBAJP8stNDdVwmaENXTQaUG" string(8) "uruvjafk"
Output for 7.3.3
string(32) "wUmwarU5fUChbUVcxqWDE1b6EkC9dI0l" string(8) "lkiuwxqh"
Output for 7.3.2
string(32) "5Uheh1qDIugFUG6fU4Dh0hWrZ9pTolP4" string(8) "svpzrmer"
Output for 7.3.1
string(32) "HOcrVvRLB4VXcPzZD6tkjym6zzIqxxN1" string(8) "gbvguiwn"
Output for 7.3.0
string(32) "xBU82gGR8xBqd2YRErE5G8XnCCOQuupL" string(8) "ozqwymhn"
Output for 7.2.33
string(32) "jo6ePX8af1JfEOsYlWP08n5kMzq6B4yV" string(8) "fxjxjqdd"
Output for 7.2.32
string(32) "84j20i348gkWUphLeEwAw3L5XEzKkzUD" string(8) "cmccijls"
Output for 7.2.31
string(32) "KyHPjsFY1tGMug1jzEbVPs9QS0D5npae" string(8) "ovexorka"
Output for 7.2.30
string(32) "atVITPj6pMbo6Wv9mf9GYqeWWbmlYYGb" string(8) "woaakcal"
Output for 7.2.29
string(32) "wJQLddQjctR809v3fILIss55ut3iJurY" string(8) "jbmpvdxt"
Output for 7.2.28
string(32) "mzVRPmflt7vKg07C8RjZ3hqgyQESH0nQ" string(8) "cxnmhtkc"
Output for 7.2.27
string(32) "a7ngFIkCwJj36WgXyGsEH6JiWB3bQXJi" string(8) "dpqjtzrw"
Output for 7.2.26
string(32) "BjGerViyEzvmm5jshRdQdcGir182gGqh" string(8) "kwomhmef"
Output for 7.2.25
string(32) "vWVS1VvJeVohXBJXcPDzxjW82v5vFbhL" string(8) "tnaernic"
Output for 7.2.24
string(32) "g83ysnLPjcKywR3YfYelouVOq4WsLT5l" string(8) "aiazxari"
Output for 7.2.23
string(32) "pFbT0oKYMLXakY1Q9WoydRGf4dg8kyDl" string(8) "wctdzyqi"
Output for 7.2.22
string(32) "As8tyC41gdB6ALDnfcIbxjesceKvRnpT" string(8) "epttqrco"
Output for 7.2.21
string(32) "oZdrn1NH1rnoiBrP7K2o903BOkUqhuam" string(8) "pnvhfwiq"
Output for 7.2.20
string(32) "p06FX796k6po37x6fnrzQAmyYysSNyfQ" string(8) "epncnyzo"
Output for 7.2.19
string(32) "x4nhjT7DBOqrpDg2qpyRUvRQIxdVH9FJ" string(8) "fianfpha"
Output for 7.2.18
string(32) "W2F0dAoJz23NWE041YUxd2Q12Bq9VWbC" string(8) "gajciiht"
Output for 7.2.17
string(32) "D5PsIQGXE3MeuFplpCnjC5QZjLkvtad2" string(8) "plrjskmq"
Output for 7.2.16
string(32) "MZY06OMEHKbU8VG0fnUxr6z46F9Mv1ID" string(8) "mzdcwnak"
Output for 7.2.15
string(32) "siea6QsSzqlUcXtt4ZVx9K8gOVx7RU9k" string(8) "alxmfbnt"
Output for 7.2.14
string(32) "OQLT671yKmaU2s0oBLksklGb6iLL3rCf" string(8) "kynkbekl"
Output for 7.2.13
string(32) "Y8AVUhIMeDMcz81zScLZJumRnQuVUJg0" string(8) "mvguwgms"
Output for 7.2.12
string(32) "wWZcFQQwEWLRYdQjvg0TfJhbwMvNCCW8" string(8) "hjueefot"
Output for 7.2.11
string(32) "yGsHTizhjTpks6yzvze9LiDBblvhjUYm" string(8) "cumqvgqt"
Output for 7.2.10
string(32) "uz6VU9WC0yxkAjshtglk9JDpo7B9sueY" string(8) "ujkbbzlm"
Output for 7.2.9
string(32) "NxfvPBr5O1dGRsDY6RF0YBGM0K8BMmob" string(8) "iixcbypx"
Output for 7.2.8
string(32) "5zXcPA1yYVHUpq15YFuq2LYXy5Hybhfj" string(8) "ygnpurjq"
Output for 7.2.7
string(32) "vBKc0DF6WDHk4aFB7dMVgG2Z0xIhBKUD" string(8) "gjfnfvia"
Output for 7.2.6
string(32) "nLPVkrTX545KsUkHVkF39BBYY8di4xJI" string(8) "tmubzcnr"
Output for 7.2.5
string(32) "n1xMxGaZXlUXn5KZ2uSaV1SpfPZTMd4m" string(8) "xzkccdhv"
Output for 7.2.4
string(32) "dd7j47SAEWrJMvWUe61JlKxxjLxiR13F" string(8) "nmotwswd"
Output for 7.2.3
string(32) "8mDWOQAnBFDMBlOaUj54y7OQOJs4apsA" string(8) "yvxhmfjn"
Output for 7.2.2
string(32) "LIoxjCgtaxRPm5giahlQokbv6iBuhATw" string(8) "ugjfwcrp"
Output for 7.2.1
string(32) "nvt2D5mvRaT548JbCE1oRaZN1OQH3iJU" string(8) "txtmcimw"
Output for 7.2.0
string(32) "efFuyQNEDVSDhJM1zj0QqY7KmExQ6Zor" string(8) "jnyismdj"
Output for 7.1.33
string(32) "NRUlXY6dz4CqrEv9yVl3CnZ1X6imXTku" string(8) "epumdzlc"
Output for 7.1.32
string(32) "k2dUuAb1bmD002fQ805R5UchLKobcpWm" string(8) "zzdvrisx"
Output for 7.1.31
string(32) "7I24XlsOjSSne10EvVfQjhkoOOaLcKUm" string(8) "ohallotb"
Output for 7.1.30
string(32) "xhTiSLQQKghlK8TYLmIZQRNYCxbsrH1C" string(8) "trhapjaj"
Output for 7.1.29
string(32) "yZSxHFfrdrBNeeQMhDVwXzjKnXmAoG3Q" string(8) "kqicowth"
Output for 7.1.28
string(32) "PvoDH6p5Ji1VgP1Hymmy9Hte9KNji25P" string(8) "zuegrcui"
Output for 7.1.27
string(32) "RkKGUcPfSDl8HfZhW4Dd7QtUEaew8YZX" string(8) "imghiyvf"
Output for 7.1.26
string(32) "1d631ZSbo0NAi24vA1i3tPjA5tGd4aI0" string(8) "rjuomemc"
Output for 7.1.25
string(32) "RrbR6DvS0Ql3ix1xGynZbspKtzmm7xdm" string(8) "cujuwqwa"
Output for 7.1.24
string(32) "3SzvQR9tHfYpsDKDxdB1pYaCMBh4ivii" string(8) "nxouhjwe"
Output for 7.1.23
string(32) "Q36zpzsbYv1V9UPc5J6dzhcVjUmuvITB" string(8) "ntmngfxl"
Output for 7.1.22
string(32) "pWiDlpVqaOtEoma1ASwTrzu9qA4tvqW5" string(8) "cbzwoixm"
Output for 7.1.21
string(32) "ovjYe4UtcOBSOaazZgJi2rCSC80n6vYF" string(8) "eulwzamj"
Output for 7.1.20
string(32) "xi32ztoZTpPLlxXWk9AVTdLu77bagnam" string(8) "bpjeqgwh"
Output for 7.1.19
string(32) "VpIFYPPGlxccwP8G74AhtAU1IfCdXBxu" string(8) "vnzhubjz"
Output for 7.1.18
string(32) "dvmslJVW74nkptyEyx94Vids1m5VpTPB" string(8) "kelcujdl"
Output for 7.1.17
string(32) "ndjK9UspfYiJfRPcNBhd2tNZux7MDuLd" string(8) "clcoijqe"
Output for 7.1.16
string(32) "x80kyAzp0tl8xCj8oGkTxor1jg02pQBI" string(8) "eyotftlu"
Output for 7.1.15
string(32) "LCrBEsu7JEo8E1KNyEFMvMcAFTomKQDZ" string(8) "pfncaihk"
Output for 7.1.14
string(32) "pbFYSxyYARIz9AfA4u1st44qtJec9Q77" string(8) "vgyoqhzg"
Output for 7.1.13
string(32) "fI7GIdxEIhkM9MmkbmqQVuZKVcx0PXGI" string(8) "kijpqczu"
Output for 7.1.12
string(32) "DWTQUpR9yZiy2Z1pWDtDNkoKmmhJ9IZA" string(8) "mcrqrksx"
Output for 7.1.11
string(32) "VwbzZyafRywyaZ3PpjoWXxFVgOrPu5sk" string(8) "qcsicouq"
Output for 7.1.10
string(32) "J3xpKVTBzsbU1TnYYAOCeHYFgR9issNQ" string(8) "gvwteety"
Output for 7.1.9
string(32) "KtPiXWbLt3lEl0UppO1L20kZuPpebmOp" string(8) "furvdpdy"
Output for 7.1.8
string(32) "BqB2ExUYwDa6CqlzteW4sUknfU9nXuJ6" string(8) "mxyzylun"
Output for 7.1.7
string(32) "3czMh9XZYFOsJv3tR0guwZRDvN6VDdFg" string(8) "qngwdzxx"
Output for 7.1.6
string(32) "McecF66c3Gx0s79nWndYP7rvUsaAdIFg" string(8) "pnjskuqp"
Output for 7.1.5
string(32) "EjsHoI10t1dCnCe9PlKdUh5JSMknH0mL" string(8) "ofkqlude"
Output for 7.1.4
string(32) "mMTUUaAY78teSx4mje4Ndvr3SwXKr4NG" string(8) "yfaeqdcv"
Output for 7.1.3
string(32) "nhCPE4W1uDHqcjjPoyU4goXilOPvBTz0" string(8) "psokeqzf"
Output for 7.1.2
string(32) "bUcpHHT2UENtireY8MsoqYbp2sLiqutM" string(8) "stlctyof"
Output for 7.1.1
string(32) "snibF36VDhQT2pQIMCsuma47RtxM6tiy" string(8) "ygxxwvvx"
Output for 7.1.0
string(32) "9zV3oHxQWMBipE5QVHR0vtJHvoelP5Xr" string(8) "xnlllphz"
Output for 7.0.33
string(32) "Dx7o6h9YOaUHXmIneWqjPE9eI0SRx3wi" string(8) "tghuvssb"
Output for 7.0.32
string(32) "XH6hSDPfwZsunsdNCrK06xZzd4PnOGgz" string(8) "qrpdqkkn"
Output for 7.0.31
string(32) "Z9lRiykxSgdoWoyNoC9zVzOxLSvckUy9" string(8) "rgbymvcd"
Output for 7.0.30
string(32) "MouR7abjKvfuXNFLUJiAUFh7P3fW59ID" string(8) "bpoojhoz"
Output for 7.0.29
string(32) "Su7Ezgm0wnIjfCv9fwpz2xn0bxdKPjta" string(8) "yqptboro"
Output for 7.0.28
string(32) "AqRHHOJzu7LMEkhRgcNpzHqGzPZWmC5J" string(8) "lqqrxgbc"
Output for 7.0.27
string(32) "G2DIAMhEG7Y5oHJ8wcEKT9EitxD5AppG" string(8) "jfbaxbkg"
Output for 7.0.26
string(32) "Jq4grGGRVmYGzoCLH5iWIVqMytoKzZY0" string(8) "zlwzqaya"
Output for 7.0.25
string(32) "v4xY9pqH5RUx12ybDhnxp5wTb8EsNKRX" string(8) "qekvbhku"
Output for 7.0.24
string(32) "wcK6dZQjCIxHkqvf2aQfoWT1QaVUqrll" string(8) "mydelnhu"
Output for 7.0.23
string(32) "TiRuEGcAJ8HMrCs5NSENMt6DrQuO0xKo" string(8) "uzsdnrru"
Output for 7.0.22
string(32) "ZyvYYiuBAJcTGokgiExOocf68f0qlOQJ" string(8) "lbhctdli"
Output for 7.0.21
string(32) "TAuM9YNuvlA02Tz1wa6cmU3J2HuT2nPy" string(8) "rtvxzowg"
Output for 7.0.20
string(32) "xBbbCOlER6u9gwcPPZfbdRtKDdTSfinS" string(8) "zgfclsik"
Output for 7.0.19
string(32) "JsUh61fLmWrTGgXQEnXUBr3zCGaI5ZNw" string(8) "zjyaufqn"
Output for 7.0.18
string(32) "1CuBetsqNICC3faCLUbwiNx3Cs7hleYA" string(8) "fqjogclu"
Output for 7.0.17
string(32) "M78HiB574AZQfZkQGp4NT1igNsnyF6kT" string(8) "kgttwlce"
Output for 7.0.16
string(32) "JNEePB7YqvmzRku7K4FBR9clrDIa1Shr" string(8) "bqzdundf"
Output for 7.0.15
string(32) "1TMzYcUCVOtQnMZWFdPXJd4VA94TMXxt" string(8) "eutmqlic"
Output for 7.0.14
string(32) "63WY7ujsiY11hvLvYLq6BfC7RdTeBcBI" string(8) "wqprdtft"
Output for 7.0.13
string(32) "Clt5xIe38XyibKVz30L4CL56Z0y6FXSS" string(8) "zmtdxzgu"
Output for 7.0.12
string(32) "6vNb1iAp7QXHjUzOsbwXCPvjq8ltWFG7" string(8) "xxcrjyip"
Output for 7.0.11
string(32) "rxnofQtYvxj7aCye8KsZ8YpldEehGjVS" string(8) "gkosbpjz"
Output for 7.0.10
string(32) "zV8TDh1qti5C6zyRBthTvXWAr3pu8cdv" string(8) "zvrzsjjc"
Output for 7.0.9
string(32) "4RBhLensZQk3YCNZtwjNgcMthdYUfv39" string(8) "xrcjawig"
Output for 7.0.8
string(32) "gg0iTbmEfiAGArK0N1qx2OUb7JYJLByW" string(8) "fhtwndoe"
Output for 7.0.7
string(32) "Cq5jefN0Lv5MvhA9yFqdGh0BjMg8d4hH" string(8) "phsaqzbx"
Output for 7.0.6
string(32) "JtgKLOMGnKaCLxlRmtbGcpMEulRHzs5t" string(8) "fzizlgmw"
Output for 7.0.5
string(32) "fEsBdB5UMWSWAyaL9ostImtLyzol78h9" string(8) "lfmbzfyo"
Output for 7.0.4
string(32) "QntJjYvdtfcFHhpLPPU9xvn0uhD0Tmse" string(8) "syfdiacp"
Output for 7.0.3
string(32) "QamyOyOQEXDo35TH9FcNUQNOQiE85WeT" string(8) "ovgutqoe"
Output for 7.0.2
string(32) "amc7KJYdwGKFoPlw5xg4ivg5DguTC7we" string(8) "qukwhgso"
Output for 7.0.1
string(32) "3DWx3qmmiSBu36BB8GoflO70WX7CbYV8" string(8) "dyqeyzvm"
Output for 7.0.0
string(32) "ehjrkCKVKdSvS67APOuqEYWSqP4wJBwt" string(8) "izlofwbt"
Output for 5.6.0 - 5.6.40
Fatal error: Call to undefined function random_int() in /in/b4PST on line 20
Process exited with code 255.
Output for 5.3.29
Parse error: syntax error, unexpected '[' in /in/b4PST on line 17
Process exited with code 255.

preferences:
69.13 ms | 611 KiB | 5 Q