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( int $length = 64, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ): string { if ($length < 1) { throw new \RangeException("Length must be a positive integer"); } $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } $a = random_str(4, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $b = random_str(10, '123456789'); $c = random_str(); var_dump($a, $b, $c);
based on f7tVG
Output for 7.4.12
string(4) "IKLW" string(10) "3921223788" string(64) "4xmwP86mNqM0G61UAP8OpzSBy8XtpyIUVk77ghGkhNNB0hJAs4cRsGRybQfxbNEg"
Output for 7.4.11
string(4) "SEUO" string(10) "4487567696" string(64) "Q0wTQgZuxuBbl3Dqj7pldc9b1EKONpM7OQ4nTfTX155SVlDVxM65K1kLnmNT3WE3"
Output for 7.4.10
string(4) "EUYJ" string(10) "1289421288" string(64) "VAPUmXh0rkzakAxTI98uZuUqlo12seIHBv0DkUO6rFvb6Nla3rhgMkxF6HCSm3kF"
Output for 7.4.9
string(4) "UCQJ" string(10) "5414125798" string(64) "y5JfPLJxzeh6TQDKPDvXsyBUtMTS4MdlBj8SW3WTX9JjH2jVq3axxRMsVGPCYbp1"
Output for 7.4.8
string(4) "CFAS" string(10) "4469371539" string(64) "trojs4NAm2viHPtlyMPXm1YPVxn1UOrvZWPvRD0WsbX7DkFUQy0PVZCFoYOSDWvq"
Output for 7.4.7
string(4) "WWZC" string(10) "3444871991" string(64) "0fok2U5dQTkkiwt2BMsXzXpdsM47TYgkmAu0wIXXRCfG2sL5NjepcVOheF2j83FY"
Output for 7.4.6
string(4) "EQTR" string(10) "7512413846" string(64) "luw1qqvU3MHjwS052newcHyBmywDgeYy648xukPsU8BepsBq8j7ea2HPdbtf8Wi3"
Output for 7.4.5
string(4) "HHBO" string(10) "2515642491" string(64) "0XP4n9boFcthIZhBuGf8GMLoYU28cNuGV1QkEJpsgZr28HCtDwJW3Lw6o9NXpVDT"
Output for 7.4.4
string(4) "HLOU" string(10) "8343153177" string(64) "cFAdi0ZEPLOf6aFK4hP61GAxDZFQTNyMi4ysNyarhHsRxvpxqFefaW9sHZppp3Om"
Output for 7.4.3
string(4) "BMGA" string(10) "9936643611" string(64) "6dzpTjyy5g9RVVLq0cxDjJkv2sZ8lK86OMmVJ4SFC9XgCnrmUg5zj49FK4r3HG0u"
Output for 7.4.2
string(4) "FGYE" string(10) "2541474275" string(64) "QLoT5gMFjeanThUCM0GdwSJajLUTtQF9bgDuDUmFM8O09MKURKtWTe6UE52Pk7Dh"
Output for 7.4.1
string(4) "VIWT" string(10) "5454741333" string(64) "wRtGdwnacky42QVPNJCTkfMxgQpCtnt8lDJPrwNRKLSjqLcSULA0mtqIH289766p"
Output for 7.4.0
string(4) "YBVA" string(10) "2417359345" string(64) "cQagprtUwfNWTHorEydlh4IBxrkg4H8hUNX79E1xZGG5ofYCP8wsGBoch8BxpPOd"
Output for 7.3.24
string(4) "VTTD" string(10) "7424193294" string(64) "gkmBkiH9HB8ofLO9NUBMJhY6qaH1wb4bnwrUEbZIjxcDfppBwMdcq4TioB9rQChe"
Output for 7.3.23
string(4) "CORJ" string(10) "6271757134" string(64) "gY4PLiovHxj5Ley23WS4drrBovXqBs5hHQBSya7bfwNqPMvaBY12jmTgd442mLN6"
Output for 7.3.22
string(4) "XJNL" string(10) "4241535722" string(64) "nvQjmjGwEsRdN668GwuEtOJsTkHELbJlyI0AauDssy3Mk1PVZKaAlLi1gxzIQm5f"
Output for 7.3.21
string(4) "TYQI" string(10) "4853712123" string(64) "6F5kWR7iGopPufscAhp7Pc3kzPlALBllRdgzKYZ9rsIda4kmHGrTZRGwc2oZ5AB9"
Output for 7.3.20
string(4) "QGYH" string(10) "6459535912" string(64) "iIUu9QDjac1Cucy7JE7FNtYmJ2EUnSSBbxSlC8LNllX0K9EQPR6ydNprnMry8WQV"
Output for 7.3.19
string(4) "THSA" string(10) "7625832783" string(64) "Dzek7k85LgjqvJ98z3Vlk3bQPzmeYY7b29UYDhZaLL1wWfe4hs89F9E3Mx721vK7"
Output for 7.3.18
string(4) "DDWR" string(10) "7234627165" string(64) "Pkmf5RGFfJzCWJzrejgRtT6RiF0ZcHqbuNkbtFGBahgNmZyKqBTR5AEzEjkU28rj"
Output for 7.3.17
string(4) "NVDC" string(10) "6952535572" string(64) "xxC7DuMWGwuMdQHjCRB1NP2MpAlajumbj84U000Lm7rVF0VmHbpm5Z0RDDjHdvDQ"
Output for 7.3.16
string(4) "RUIR" string(10) "7185682169" string(64) "98PiU1MacDl3nqQc2y0iiyeWrlYBRWTFtua3Kf1RF9iuwUUoX5rrKMrE4mbWYuxB"
Output for 7.3.15
string(4) "FIFC" string(10) "2235734555" string(64) "AoYGHgjrE1ixGEf9Xv2YeDyxgGa1cqu4FlqRggNckTxvyOyr8noqmfuvmuxmPgwM"
Output for 7.3.14
string(4) "MQNQ" string(10) "6149759633" string(64) "KgYnWzV4ZzED9Fm7VrAPxqZuq3YGq5GRrVgk1NP5VVhz7PJhcwsP6zZmM6F5Yybz"
Output for 7.3.13
string(4) "ELLL" string(10) "6647392126" string(64) "p7bVrO1f3yD9SGQUjtq2ifMXSN00BOxTVxTDxo3vEv31lrsDPCYVAx7A2lsl41wK"
Output for 7.3.12
string(4) "ISSH" string(10) "3756916657" string(64) "Hl3Xxdh4LV8bdDLmqNgvve28iQZrj8zKyQwr6gxPOJvFxIrgzDAWjpMSZKuqiE6h"
Output for 7.3.11
string(4) "TPNR" string(10) "2817888176" string(64) "IJPnpDhFCtEwIlOS0JgKjGLkLX9ueTWHHfXUAF80ZQEIzgiDexJ51kCa6xQsXAmi"
Output for 7.3.10
string(4) "HZFL" string(10) "9252956365" string(64) "wJSxFaKD7GRJemHNSwbXpAOftWR6TnAawPua9pv8ILaTYt58hwx6z7e17FMVEvh6"
Output for 7.3.9
string(4) "KOJE" string(10) "7278864827" string(64) "0B3bWrRjqRZJOc5mj6OgDsrP8p2OrrjCS4XfAQwpT0PU8PFmFuwkkcJTPIgszxCo"
Output for 7.3.8
string(4) "ZOAV" string(10) "9319628475" string(64) "HOZ2qZIuip9VuEyFxT3ZyxLKe08v6gNsGvWcZ8KXCkTZEEZUcg8R0vPaiOqyezDE"
Output for 7.3.7
string(4) "GLYV" string(10) "2137493263" string(64) "gCzwroDrvvpfoY2CS6KdWVDqA8Xht2nsP8pkMtvCeYWIhpPluixoP1Zbry4qmdt1"
Output for 7.3.6
string(4) "VOGF" string(10) "4179819856" string(64) "S6PMQEZh7rOEf2n4T7hzg5YTvEn6NetHAIvK33m4L1KgYKz8okqf6Ljt6U8hTQDP"
Output for 7.3.5
string(4) "CUDJ" string(10) "5147425886" string(64) "cideLcCTef5d3IXA2lm7BC8aBpdVd0etoVk8vMn705AeIU9DIGyaWNFh6tkFRYnv"
Output for 7.3.4
string(4) "EEPD" string(10) "7434739588" string(64) "xGbjfD9PSrrh0bvSR5ChQO2yxHjMJPQHE5iSMFoI0hE2dDq9BsrvD5FYmFRIEFWW"
Output for 7.3.3
string(4) "PHRA" string(10) "8533464425" string(64) "fZvVL7YvLv1QKpr1xyLhc8qcFE7Pgl6OlROmAYewnoiYxaYlyahslnSz5Ru0qGgl"
Output for 7.3.2
string(4) "QALH" string(10) "1993845939" string(64) "jIbtMmh8cdSTalL9DPqrDIUk1FiQZVIfIyR9AAJSxEPm2uNwOKxwNKclugwhP9zl"
Output for 7.3.1
string(4) "KINJ" string(10) "3548576126" string(64) "NL0z1sbCjrw8QRahbqbw9MIBzkyP4GnWWqjhougpWjq4ryuC7JEEB25erWpz6J9U"
Output for 7.3.0
string(4) "QNZP" string(10) "6519913686" string(64) "ae3DMS3gVgU14d6V9r6XeOOXlOujj9xpG8rqGcLw2fT9eVZgWMBeYt93v3BCrKzA"
Output for 7.2.34
string(4) "MZHP" string(10) "3738835381" string(64) "hePUsuq6sFL7ypJyQ57JPd4rbAlk6STtL2Jp7uEXmCagwdy9HzXUUNFY8nKcj8MY"
Output for 7.2.33
string(4) "KLJS" string(10) "8826567574" string(64) "tThcmfXC9LKNFNaatd5aP4qOz7EOLnKTZmKPyTZGgyIMpUVEOjmRidnjEBPei0aY"
Output for 7.2.32
string(4) "TWJF" string(10) "7111756657" string(64) "X0MT7nffMvQ12RgWOzyi1fyO3EUq8OhHvdi9SJZZNUzSHdDdERH6NRJZ7Ac0Cvqi"
Output for 7.2.31
string(4) "FZKR" string(10) "1457491152" string(64) "zEb7rrxzhMp0srkwogqGkAQa2WsndFMTxYDMRTkgKGBQdMTVXyWdGuSaynl89mnp"
Output for 7.2.30
string(4) "PUCX" string(10) "2842139552" string(64) "bQDyccTqRKUZT7IuuOHue2PU76JuhogMCl7Yipa2bUUBHX0sbLSXCnPBPyMXjkBE"
Output for 7.2.29
string(4) "LILU" string(10) "4688349659" string(64) "Z5JDIWxG28ht1PoWfgTXCZnezqzO7wh6Mn2AgqRZf50zgskcYcTgirQOwNTAInUi"
Output for 7.2.28
string(4) "AZTD" string(10) "8245457717" string(64) "RL4pMp2NNcCUeCKp1kG94rLRNe3N7EZzF9kV18tTWE2R2KhKFmzJrlvRz250rnfD"
Output for 7.2.27
string(4) "UYNS" string(10) "4988363837" string(64) "bu5xOIMiZ117gLLrQC67QolkczYmW7ORBs6ijrvaUvL5E4LqHDzS9ayETGK04rNu"
Output for 7.2.26
string(4) "QCQS" string(10) "9367821851" string(64) "SwPIzAa5MvuPq9TnFSULehMqQ4R2L2ILOjRsXaUCbXzZs2iDJELRycHyjoz1mv5h"
Output for 7.2.25
string(4) "KOBQ" string(10) "9441174356" string(64) "fKVcSNuidX4HXxKv5cue4lJa7zayNNwGQneqlKV0HnI1i4eRznBfNh1BdeMohywb"
Output for 7.2.24
string(4) "MPZU" string(10) "1187511459" string(64) "uqpr3pontdMbiTYmQNYS8C8PvqlY2upeYivJbjP8nOmsvHHi9yLXZ15koQByTfbb"
Output for 7.2.23
string(4) "YGWO" string(10) "4916438322" string(64) "5BXEYeNQaEGPfMPLMLwpnuwX0O46mRHHvyKrRENzil0mlY6OGqkH6od6oLJAbF7B"
Output for 7.2.22
string(4) "YKDI" string(10) "6551758872" string(64) "beLwEmCuSp1ZSKFaUy51aojcB4big09lOn0r6uudUQPopQXOi6F12IblMerwwoB8"
Output for 7.2.21
string(4) "ZXBD" string(10) "9463734813" string(64) "jku4nQIDLrO6LH8Ni5UL6YolO4isSz8Cet9kWFXl8Ls5qVnPxR4yycdwhN4nnJHl"
Output for 7.2.20
string(4) "PWDL" string(10) "3321422312" string(64) "aX8nhFBeBnfyErk3kN7fBtxsr2VrEMGYGxjAByW7LAv9svJPeDV7g7Tek8A2hudg"
Output for 7.2.19
string(4) "LWZN" string(10) "3142759365" string(64) "mPyNuqrZ9NYVPP6MG54siQoYg8aogDYRWVMa1iBt2Whjbd4vy6c1IabmsHNMBTas"
Output for 7.2.18
string(4) "PLHQ" string(10) "7953249738" string(64) "qb0lGrFnxsbilMpPeT8vwr9l1vJv5yLzgHJUYgbEK8hMq97Rrdg3Nwam3ry5IO1J"
Output for 7.2.17
string(4) "LNNA" string(10) "3516951718" string(64) "3wRrl9BNWudZTHjihQsONRDWO7Zyyrzec2tMfuC6ggYMQl0L2h2Uw0pADzQrKlsl"
Output for 7.2.16
string(4) "RIRO" string(10) "8592752892" string(64) "pZVtt8S3KIx8jfDOTBsKizKLG7a4k1btWuPvjFijCXuvKrzMILvFqDTGgvZa7e8x"
Output for 7.2.15
string(4) "DCAA" string(10) "1853534678" string(64) "3gRMmNaL1SfWys5q9oA0YVQgp10PEFvKekKhHW1wipc2J2IfbdYaLt1k422ko25k"
Output for 7.2.14
string(4) "GCEL" string(10) "8426879118" string(64) "IpbCi8WkYGFQNz1NWnml4fNDNiJ9DUSIsPEnuRdjOxgGlMOV6DQbpnyvi12i5Z8d"
Output for 7.2.13
string(4) "AIRU" string(10) "7465247946" string(64) "9uUZxjoGgDq8l8HcjXwGnvNOTXWmozmUjYiiQQdEsDSKfDoEIXT0nrx6Bm52p12B"
Output for 7.2.12
string(4) "YXVL" string(10) "5729984829" string(64) "Nbu0PvZ3zeqNsH7W2YDyGNc9bZdROcLpdXv0XP6wZoR7V3ifxLxDhrRas2z9gVbi"
Output for 7.2.11
string(4) "RMFN" string(10) "4696732512" string(64) "xledd3WcDtH6Qsmbg9UH0KOm6KTlUKcvxcfwb9QGScfGsksgyhBkyLDUcR91ZC6t"
Output for 7.2.10
string(4) "AWZF" string(10) "9998184822" string(64) "ZPDrdnkXbr36sueN22rKgolxn1dZHMIR87hiC7haM3LlzBsYcRTdJ9JmUzTAQQ1t"
Output for 7.2.9
string(4) "UPRB" string(10) "9791316431" string(64) "qWTTkztZ1ON8SqdN9HDTCWSkokc2hnQ4QtNOOySnF48DDKuhMDwq58aXiYBKswCO"
Output for 7.2.8
string(4) "SFOB" string(10) "1222191722" string(64) "OquxMzw0kmrJ2fpgM1fFEWYQP4XJ5x8ZlTW7WSFr7ahBaUDIJBzDGwOhKl9pO5R6"
Output for 7.2.7
string(4) "MCQT" string(10) "2644726779" string(64) "c8vvM3PlclnhcefnzOoPMkrGV7bZZHxNWhoxxPoS8cAarZytGbyNKxdMqvwDqRVK"
Output for 7.2.6
string(4) "ZQFM" string(10) "1679735594" string(64) "o3va8KuUEZUu5D4i0ng6PuShL8qzhT9vXASNRBxaw6Fz0IIo4Z5iJVfxmJNUVkwh"
Output for 7.2.5
string(4) "DJNZ" string(10) "3957384669" string(64) "I32YgdzTcBqrxxGdLsEyNvpZnYd6AsA8xShi0UqObhl4Mzn7th6r5PemIH9pA8JM"
Output for 7.2.4
string(4) "DJYD" string(10) "7757499255" string(64) "h6PxlgPklKKC7BlxkZubg4YqRm6KthC0f5Jal50FkhxppEcsWITnTuMdpZssJ3ZV"
Output for 7.2.3
string(4) "UUNV" string(10) "1242566142" string(64) "MIiev4ZasCHLvoOWDV10UsDSO9nzPqzyjqN7HgubRoRbVYQ3VH8kiYe34vQgvZcN"
Output for 7.2.2
string(4) "HBML" string(10) "8458878322" string(64) "t9vEnvftZ8rKeLqLPzNXfbKPqk98QHlVaY1qFlqvCZ87dxidsIVNKu6b8QGIR2hV"
Output for 7.2.1
string(4) "VOKV" string(10) "1916265842" string(64) "i7j9SPf1ugHyfhXd3j8hYTyFg6QLMZkOzm0hvJuW3ZAKjpSCGqzeCpD7AyV9OCaU"
Output for 7.2.0
string(4) "DSOU" string(10) "8726681345" string(64) "Ga8cPAGpfuzIFENIfiQFdTY1SLqSsrn8CBtzXSBszl4KySRxUR1IwAKLjUGYLnBn"