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 7.4.5
string(32) "yBooWnp1533IYnQltkBWeMOomVjECY7R" string(8) "tldlviit"
Output for 7.4.4
string(32) "fpJ1yGm81IbMO5MUzdFcZbGx6IhoTdRs" string(8) "ulwtfsrh"
Output for 7.4.3
string(32) "IyaFWPZt5iWdZBICJqTIpQHA9Z8HnjST" string(8) "kcajsddo"
Output for 7.4.2
string(32) "uMs9vJWUqwIUQcsqL9yqWeDY7FgRQRiM" string(8) "akfcqeqc"
Output for 7.4.1
string(32) "GxCSu8jf27UOjhnv9C1wOn7GvhPLWJou" string(8) "pfmnlrmj"
Output for 7.4.0
string(32) "YruylZvPCWnNL8m9DaH2RSZnxOBvRF14" string(8) "eqasywps"
Output for 7.3.17
string(32) "toxFUl9DMOrcsoa8irchH1K8F1D2kYqt" string(8) "zlgtpysr"
Output for 7.3.16
string(32) "RbVL4IQewwALLQGOaOTm6g32xEkQFiHf" string(8) "fsxulmyu"
Output for 7.3.15
string(32) "ej32uRn76xzFMqY6NUmIe4aPCiUSj4Cm" string(8) "jldtqlpa"
Output for 7.3.14
string(32) "93Uk4fIaE5rZTq7WAni1z2yeEaa18gl0" string(8) "zadilykv"
Output for 7.3.13
string(32) "I7TyTCbRhARoCCYkQDBrFuycFwDqIWNx" string(8) "plvtxkjx"
Output for 7.3.12
string(32) "Mpzj2ZPJ3BMnWH0nfcNLRVEATyEnkPwd" string(8) "gbjvqndp"
Output for 7.3.11
string(32) "Z6CdQRFPbMY8l9rAA8MLdO2Zu5FjAd6H" string(8) "tgzynmzm"
Output for 7.3.10
string(32) "tUQMsKOAeo8aPE1U08Ksm8MSmtVB6zoK" string(8) "sugspmit"
Output for 7.3.9
string(32) "lMa5P4n3S27cMXZSZr60HA3DqN6KWXwy" string(8) "ekxunuwy"
Output for 7.3.8
string(32) "0NMKLubvGeHzrYi4oiHxFkOOGv6XJeAR" string(8) "ojcdhunm"
Output for 7.3.7
string(32) "uEYn2sMRkmdUPWD9UQ7wYS4BFQXp6cGu" string(8) "ducxblgs"
Output for 7.3.6
string(32) "J384BlCE9cxnq1jMNNOD3xsAwCSsK2K1" string(8) "ekpkayad"
Output for 7.3.5
string(32) "TqVtPer5WAJ9Jc4bhTzrI3bCQAZx6XQa" string(8) "kckfyfdz"
Output for 7.3.4
string(32) "XfCwUPhVDfhOLahp3jBPvUbiOE6XRwXf" string(8) "uyahawed"
Output for 7.3.3
string(32) "vWbcA23J7NcD17RaduYtAPg1skcLn10v" string(8) "osperrxe"
Output for 7.3.2
string(32) "LnYJjCBWb5aX46x47zThAAIdCzEDxdr2" string(8) "sxwcssgt"
Output for 7.3.1
string(32) "llfI89MwwOg9NpnJiLwWdQuw89nodIgr" string(8) "abuvbwff"
Output for 7.3.0
string(32) "uWLgm3FTx5RjZXfHn4ikvr8S3BKmK4G1" string(8) "lzpcoxui"
Output for 7.2.29
string(32) "5FMoEtZLvHHKOSaaikyOf3DsUL0j28TY" string(8) "vdzzsihw"
Output for 7.2.28
string(32) "3uj0TsjdPDk5hWJZZF0dI1APRBIJg0zm" string(8) "ioljzghq"
Output for 7.2.27
string(32) "gmIiUs7rBlV7g9dvOEVegGExBhj6QfzD" string(8) "dbyvmbyq"
Output for 7.2.26
string(32) "j1vzzYzElIvjQ8aNRQTmAQgxviB3yAuN" string(8) "tabddnqv"
Output for 7.2.25
string(32) "G0Zf7IK5qZ1AwRrjTrDlxVlXKSEAt7d3" string(8) "bgtfaagz"
Output for 7.2.24
string(32) "or8Q3BY9NC3U5be2WPovjBdOGxqdJwFq" string(8) "qlviafzx"
Output for 7.2.23
string(32) "mzw23V3vDoG36f26CAF4ZTqxLy0Z0awM" string(8) "lptwsckv"
Output for 7.2.22
string(32) "nZSETIlVqluJ9UXLzsG6917AyP2rIjGn" string(8) "qtnzksfk"
Output for 7.2.21
string(32) "FRM6GWCWE5Hu7rEHMilKVNDKXBR6qx7j" string(8) "bomwkrjo"
Output for 7.2.20
string(32) "43inDU0bltnVVvwYOSimLSedw7xPpQtk" string(8) "xfxxfvbu"
Output for 7.2.19
string(32) "CZQ9LW42IrnGZjiLMuB8xELT2jUFb4tL" string(8) "zxrvjgtz"
Output for 7.2.18
string(32) "AEptt1VY9At4fF8cPwODOZbL5fwOvFka" string(8) "pjeaqkgg"
Output for 7.2.17
string(32) "TA9GZSV9bEaHKmE6bHPTkvUA0gwzZ7KR" string(8) "hwxfxplw"
Output for 7.2.16
string(32) "1tWvipnTdQoTHCQaybQbQ7syS7ZmirUc" string(8) "tpjasazy"
Output for 7.2.15
string(32) "REfbfDykB1ZxDjr1R70xgwVJ5AakuogO" string(8) "hrzhfgja"
Output for 7.2.14
string(32) "9kVNCBqVB7HUjjr6UWNnJ2oMNDvoaeMU" string(8) "fsshozgc"
Output for 7.2.13
string(32) "SZXvN2KZUF07K3WZoiOkVhVrFBN9Vth4" string(8) "rjstgmiq"
Output for 7.2.12
string(32) "RqTFrfhcCL99tiRdTuIpP3jiy5pWJ8Xi" string(8) "imsjybcw"
Output for 7.2.11
string(32) "uM27mZjOVTb5zUKFOBY4pJLAzoZeX8Q1" string(8) "jqhfbscx"
Output for 7.2.10
string(32) "QyzGZDhUhbK8pfC8e2DijepycqoeEmHD" string(8) "zkjffigs"
Output for 7.2.9
string(32) "aqX70kz5IZrj0f1emmiLX7J8P7X1uzyi" string(8) "ojdkzsim"
Output for 7.2.8
string(32) "m5fhsz0kz41z3EEEhCurPf5UuWlDqBsl" string(8) "yvuavwrc"
Output for 7.2.7
string(32) "dlAbPlzXgltQiXzUpNZfdUp3ou79G8JU" string(8) "cgmekopo"
Output for 7.2.6
string(32) "nWnVYhMxaDMVdld7LH3ZkdQY9tctGxfw" string(8) "djycmngp"
Output for 7.2.5
string(32) "ybffDmOx3Gc9ErKsjVQ4UOUtRHcRwaRS" string(8) "zktuwmse"
Output for 7.2.4
string(32) "DavQEcVMJAbyrch2VHmssGw9nPT19FJ2" string(8) "hvacujrh"
Output for 7.2.3
string(32) "otlWtOYw3wOa4e9rIb77ifzPwwvo7ZD5" string(8) "kvpygrnj"
Output for 7.2.2
string(32) "2TBbNDaWomyYBwzEUc5GUYssE6Ni1qHZ" string(8) "xjgzpoby"
Output for 7.2.1
string(32) "AAtQyDH9kQTSyIujYt9FQFzIF2D2tJ6X" string(8) "ycusskfr"
Output for 7.2.0
string(32) "U3X5wcrZbp4tKNBjm9X4kmJsrYWE9fC3" string(8) "abfskibv"
Output for 7.1.33
string(32) "4XykRn1It3E5Y7AEMqYmpNeKIMEXOVRH" string(8) "njxpksnz"
Output for 7.1.32
string(32) "Xk7gSLaO7bHu6u4cukb5XE0FNr1Xd9gg" string(8) "qlhrcwyl"
Output for 7.1.31
string(32) "fcfy8Y7MDvKysgvqu3CkLjngl07Nfi6m" string(8) "bbyxtwsu"
Output for 7.1.30
string(32) "kq9b8LWzQDHtBc0LcKE99er5FoN3XgpS" string(8) "xtgjdpth"
Output for 7.1.29
string(32) "fq0JkaYNQU1NAybPNTA4rzp4RGscvukD" string(8) "lulwxelu"
Output for 7.1.28
string(32) "ayFUnZTxqJkDsPQw0VPJi4FJU8J7QUFF" string(8) "cbiqsvdf"
Output for 7.1.27
string(32) "2yK4aWXSR9Aq7uVM99P62OenqYzPLXHY" string(8) "ewkrafkh"
Output for 7.1.26
string(32) "W3GPFyCRQLma5Awn6fmeZJUg1JqCQk9q" string(8) "gducoyeu"
Output for 7.1.25
string(32) "zvsEzGS4umnTyE2AcbDLAz4dlZ3UhB0D" string(8) "uazkjmla"
Output for 7.1.24
string(32) "2rTiIhYte1uP8ZEzUuf0HAYdevRsWj18" string(8) "cauzzwhw"
Output for 7.1.23
string(32) "uNC7Nc042UeBNVIqP0zlTXARghvfNYCj" string(8) "tuaswilr"
Output for 7.1.22
string(32) "fAyKyMrwwsQvNibGFglTKvUsKvkyAFij" string(8) "whszoron"
Output for 7.1.21
string(32) "lsRUwft9VwM2hk0vrPcbBsWggFeWSfBn" string(8) "hazstply"
Output for 7.1.20
string(32) "jVKHDEgP8bilwtzW744DtoMbumM0Z8cU" string(8) "krbaxcuf"
Output for 7.1.19
string(32) "RBs3gsaMWCzr0WDX77UnnclGkX1haNZK" string(8) "vcbhrixw"
Output for 7.1.18
string(32) "zDLIfUq5WTS1VUm2sQdx3aE9WO22zB44" string(8) "oposvggk"
Output for 7.1.17
string(32) "RehH9jkAEPN5kt0dTq9ijWakQhV9yYOB" string(8) "vgxwgcoc"
Output for 7.1.16
string(32) "7RR1hRUvALXqb3JSY3nXHjKnsZfmYzpY" string(8) "trllfotl"
Output for 7.1.15
string(32) "7TWybIeLA7zrHmDTS0EVCBWM8WmoR4t9" string(8) "lomuvvms"
Output for 7.1.14
string(32) "FH7FYJHckYVtr7L7BigJe00Kx4RDTQWf" string(8) "auohzthw"
Output for 7.1.13
string(32) "1sYGYRyb4rj7FqGaAsblqEtHGUrY7sNn" string(8) "dzcbrbtr"
Output for 7.1.12
string(32) "RrYkB1GTOCOL1TtFamBD7yVv2AYJdcud" string(8) "hqkgbnwu"
Output for 7.1.11
string(32) "6PRlVUaQxQWiBFdefwZATr8u7PEVuI9Q" string(8) "dydmaamb"
Output for 7.1.10
string(32) "IZV6BtAJ4Dq9kwKoTzJWLPcgTm8yFUxv" string(8) "uloinolx"
Output for 7.1.9
string(32) "nji8Z04N9oCleRh87CzW12SJwElQjROY" string(8) "jmqeyxuz"
Output for 7.1.8
string(32) "epAnaMWbsScbXvtyLTVfFKx5uOjOYl2k" string(8) "gzfxydsi"
Output for 7.1.7
string(32) "Mtj6eG7A9essRaLmrk3sN9m1h7PIFzU0" string(8) "ampmxczc"
Output for 7.1.6
string(32) "yg5nWdMbkXApMYKveWm2bZTgCO6byOAu" string(8) "yabdfxmm"
Output for 7.1.5
string(32) "NW2HpsOHLHLLrV7Ze5QTXZghDS1jKmId" string(8) "pyrlcqpi"
Output for 7.1.4
string(32) "Xnsi6RzNoUbqq1FBJGk5YMSjBBEeuXtz" string(8) "mnwdtimk"
Output for 7.1.3
string(32) "AUDCMNKzddJ6fLBkAuyw9xDve8JUZb6U" string(8) "wypdpblp"
Output for 7.1.2
string(32) "naN1tHa9okAwiF4i8neegS4yFfNBD74u" string(8) "pglmyuoe"
Output for 7.1.1
string(32) "LBzkzkiU6pMbt9cHrf9uMsred4GOVjwI" string(8) "xlyfcfqw"
Output for 7.1.0
string(32) "G6xSozG2q3Futs0yZcBLuGV5fk5xfKks" string(8) "himmreqo"
Output for 7.0.33
string(32) "qKDjIkDDhi0cZLRUpbdpaOVMQttZptTc" string(8) "gabgytny"
Output for 7.0.32
string(32) "q7pHVVxU2aPGqwe882NfScYZ0DjlZb2H" string(8) "jrdlplyi"
Output for 7.0.31
string(32) "vpd5P490kqE4pKXX3s7q2pwBUEb5Vm7g" string(8) "flzwefzg"
Output for 7.0.30
string(32) "FVaYzu086JRyj5i3rXSBxF0eJFu0PXK6" string(8) "vhwyasqm"
Output for 7.0.29
string(32) "gNHNhCiRJJliPMKS5Yf022b0umaEs0I3" string(8) "pugzybwd"
Output for 7.0.28
string(32) "XgqTxcnWSAZSbfg9xK8tzJwQq4HgeA0U" string(8) "agoshllt"
Output for 7.0.27
string(32) "sBGXnZNGksWV0iTvsk47YN4d0Kk8jbMg" string(8) "vtcqbovk"
Output for 7.0.26
string(32) "c3bVqHfpXicpjSmei5NsQxVJ6DQrLwTe" string(8) "gmjjnjij"
Output for 7.0.25
string(32) "OXuMrg6WGIyqCzsBhrqVc6QSZyJw5LHM" string(8) "tajvzwrb"
Output for 7.0.24
string(32) "6M8BKKV0BR7D3xfrsdLWTlKPGcFqQRRN" string(8) "zlebbteg"
Output for 7.0.23
string(32) "A9AHfo0ZBtgRZQ65F5HVynJEqKe0QJ1U" string(8) "vliuvkwj"
Output for 7.0.22
string(32) "ZxDyednLNGYgPVmcFitajexbhZ0Q1yGO" string(8) "zagfgihj"
Output for 7.0.21
string(32) "77JbKj6LdOCDXifQf7Pf6wP3QK6BrK6Y" string(8) "lscjyvlt"
Output for 7.0.20
string(32) "7zOg6UPGEsg7ACJvs2kDBvgnb15vjhno" string(8) "fxvequrd"
Output for 7.0.19
string(32) "h3JFJg6y9k7lA3LwcLzg3SegYyi4Kyk0" string(8) "ajurycdq"
Output for 7.0.18
string(32) "R2wzaZDKCHhiQdyfdAdH1IVRmhaSBqWQ" string(8) "aawfgefz"
Output for 7.0.17
string(32) "wVnmPEJqcjhafbLh1cOipXwjTNYsnBw4" string(8) "qwsdodbk"
Output for 7.0.16
string(32) "HuA8wlZ0yG0RnAaW2O7dWDBRB9qwHO9Z" string(8) "lopfptgc"
Output for 7.0.15
string(32) "ElitN7DGBJR5UBSuV1ixytUka7aCKXjh" string(8) "vzndkewk"
Output for 7.0.14
string(32) "F82Hzvkf7NxDJMSSoZIJEnNNhLDtjtA9" string(8) "axtzcldg"
Output for 7.0.13
string(32) "x9qRRZBWfaRd4EYKw4meUKy523hgSGWO" string(8) "vvzxcixx"
Output for 7.0.12
string(32) "2L8JwB7RZChOz2wNtzjIo3a6GnYv1UAp" string(8) "cdhvafzc"
Output for 7.0.11
string(32) "I424tpB6Vvp5Tn14QojzhrXRsY3dGSfs" string(8) "mvdnmfbv"
Output for 7.0.10
string(32) "9OzrjL9ljS0OMipRnvqPXeUx4xpHgrwA" string(8) "frwshqyj"
Output for 7.0.9
string(32) "WoayPVvN8WV7MLdFyHMwndPV9V3Fi7UQ" string(8) "mmedtnti"
Output for 7.0.8
string(32) "83wa2dt8IS7ywWKSpFr9lvtuYMnJbl1U" string(8) "umcxnfjv"
Output for 7.0.7
string(32) "7B6L6ahtsdgM28S7Z0mwAq9FfsDYLzaE" string(8) "miuuoijm"
Output for 7.0.6
string(32) "oZjUUn3FXojEWAoYTohPVc6AaaCG9Hgd" string(8) "zcielvwz"
Output for 7.0.5
string(32) "wHLMoRrE9VaaBtYmcunf5PxJgSG2whEi" string(8) "frbitefs"
Output for 7.0.4
string(32) "yjsi8FrETj9t6MqPU09Ri6q6n4GUaJdj" string(8) "zpqouujz"
Output for 7.0.3
string(32) "8UqgwrovaV4kIyZu9JIDgm40T9me44Es" string(8) "vwrayktd"
Output for 7.0.2
string(32) "66B4FHzDf8JV80Z5cFh2YFWFo9xJT9vC" string(8) "ccukwbry"
Output for 7.0.1
string(32) "HYjf0C8rxhcUZRtYeB6jCiiFCx7MqUCr" string(8) "ydxvzqze"
Output for 7.0.0
string(32) "aAFyoRAcmh8X1Se19JvV2FjG3pwBmLSK" string(8) "lnvaiajp"
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 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 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.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.3.11, 4.4.0 - 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.