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(3, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $b = random_str(10, '123456789'); $c = random_str(); var_dump($a, $b, $c);
based on u7Oaj
Output for 7.4.12
string(3) "CUA" string(10) "1153383268" string(64) "F6mt8cLxGx6oRLdFkitgGnBLmFakF2yfreUzyNscDiDAcLRrS44vdwMscmKAQORv"
Output for 7.4.11
string(3) "TNO" string(10) "8827263547" string(64) "AHYu8fIFi00yTk4JoIRrTHeCAMVUnGcjkXUI9MH3JFsFU89FZVqP7oYa3V411YCc"
Output for 7.4.10
string(3) "WMS" string(10) "2338385121" string(64) "tThErbmQZIY2a4ovfkveMxvqGl7kkjaPgQlrvYnVlmxNlcTs3MbX4wSRM0fi5AjI"
Output for 7.4.9
string(3) "GAA" string(10) "4931745947" string(64) "CmxvW86pFN4iAVVlopZ5U4jUe8ZUD9gXzxFKJV1XIFMEzSgfz5CK5wyh8Ku1VJ9R"
Output for 7.4.8
string(3) "TQT" string(10) "2724416989" string(64) "OzRRTuIgzXxeI9I0D5hvsPZlPvey7wCNn9zL7ZOYu5IBLACw1NrcsCe5nyXyJMyV"
Output for 7.4.7
string(3) "RDP" string(10) "2649883218" string(64) "gpaqTmzJ7E0hvY4JYTcNnQNGweu87e1GuG0QYkdBalxpJWTipLGOLT3DVyMeJ8E0"
Output for 7.4.6
string(3) "ROC" string(10) "6685367522" string(64) "N1R6QDPjvIY49IEuvaFJrz3lVOu2q8L7P1aQJ7xjcm4iCX091qVvojosi5Hpst8l"
Output for 7.4.5
string(3) "VXW" string(10) "5794717799" string(64) "d9Vwve54IEC8adEH2RdKpm6o5I6Jw2hAJXcToZuvkF9Ao186bivOoAePjGO4Xgl3"
Output for 7.4.4
string(3) "FWL" string(10) "4425743916" string(64) "jCzNf15o2TCbuSjy28FAnQ44otZ47wBHW6zDA6nBHuWtLDlJdnbLjH0ezBvqndtw"
Output for 7.4.3
string(3) "PHM" string(10) "8529439662" string(64) "unI9p8r1vZLovnaBvKN1lVVFcePVB0YN6RKvD5onPhCSNZc3De0Cn1bPro0AqfL3"
Output for 7.4.2
string(3) "HON" string(10) "1334365555" string(64) "QEigUndU7tj3u0q4wquhz7xVxo7q8WQis7H0M1MCY06SDIBy9q6uOKE5Q3S7Cz0Z"
Output for 7.4.1
string(3) "CIC" string(10) "2374686873" string(64) "pxmngwtFgqIXWsdS87OMx5b2fi3fzTBYZ5KMMdSwXhLxGdJjSD8NaAb7emRWE2HU"
Output for 7.4.0
string(3) "OSW" string(10) "2525675727" string(64) "msPanj5hu5k7XNx6oQjuPw3pxkhwjAv4FnUyy5Bc9HC4kJjWhZgaVawTo2qmWwMi"
Output for 7.3.24
string(3) "SLK" string(10) "3776341165" string(64) "oqJlrNMwHbFHNYZO91wfGp1AZ2KQIcBSyRzfdmrhDpbz1nVzLrgyUKxeNTPTNjl1"
Output for 7.3.23
string(3) "YZW" string(10) "2316619316" string(64) "lDfyP9rOBbg59JTm084iONHBNjP7RCxBvE2E0vxk8xIoTaoWxIsSkd3qfhtSY2Cq"
Output for 7.3.22
string(3) "OVD" string(10) "3646531278" string(64) "Cpbyq7QsQ4v8DCmpH6CqSTMPCCfWzd4glo5Dxbhu2q2mwbNsnsQ8w7pPjC6nG1Xa"
Output for 7.3.21
string(3) "GIC" string(10) "7772941239" string(64) "qJgW9sOxOeD06KNkD4FccKWWjixiyEdPWRtpYRWG2s3hTYvmavva7tw96ds5Ipi3"
Output for 7.3.20
string(3) "YRG" string(10) "6219875899" string(64) "Ucds794UdOOPkORGQgOfAaITjcOTty99og8Wug3ZF24Ai6gGUqfHJOK1SjfjtQUT"
Output for 7.3.19
string(3) "JGU" string(10) "4762261625" string(64) "Jlj1njPs0N9oS2lahEpBEyAk85Y9d0hEYrbzttJSZpV9SPDam4Vg1ZqSvkBXWCTG"
Output for 7.3.18
string(3) "UXO" string(10) "7919881589" string(64) "6e4Qbq7nWRVEqQ45AR7k7wcJRnf8H06HXQb1MZ8rrx44tujk8ocB9YgNb0xrJVJc"
Output for 7.3.17
string(3) "XWM" string(10) "6839247829" string(64) "IIrEviPXZKHHTgGIWH1kcGXY2N0zuV3rr1eiUqoYBlFi2OE8GQggQuHpMIJmVM7d"
Output for 7.3.16
string(3) "KGP" string(10) "8493393612" string(64) "dsuDgNR1MKm5Pv6jkw0Z0bHTd5a981hJyLMUdOVQOm8XzbApVX3y36D8T3lI0spM"
Output for 7.3.15
string(3) "WMR" string(10) "9758941362" string(64) "8jHtHBzRNjYxf2C743rhueqs4YR2zP86GHWRKav9O5tujT8Zd4GZqGO1MaRjsqP4"
Output for 7.3.14
string(3) "LUU" string(10) "2594819732" string(64) "gSf6M2m01qWNh1KRJSNPQBTRCwm6T4aCWkkdh8JJHyexQ23nSMSDbLeKpRcnKupn"
Output for 7.3.13
string(3) "KSO" string(10) "8541449268" string(64) "XxX2S3Q2s9M9D0cSAU3ULudWPaOaFsiwBd47Re6nLbzFQWHhPUgtCCjeeEG9UlsO"
Output for 7.3.12
string(3) "ALA" string(10) "5137496982" string(64) "0rY1N7LpwA4C72t7taWtqeWwJUUOSQLF1T1O7oegzclcfnua19wsNAYgAvqUBxak"
Output for 7.3.11
string(3) "YOV" string(10) "8765995547" string(64) "AzPNNKW57vBHFxsJldTYLq0jsIxa6H1Ro6ehdjq3NwBDdOn0zmlvHrchyG5Q3ZlB"
Output for 7.3.10
string(3) "CYB" string(10) "1246682857" string(64) "4QddNba9U4YPLdh7gluqbLgbczaR7KXh6TpmoiDVbnVOFtTrF1I7WXWWTwVskuro"
Output for 7.3.9
string(3) "MXO" string(10) "1844975412" string(64) "FRory7xsgfLw8LjX6dhsEgX5Fo7k5MDWpxfeYnemHECwYOxl5Te7wRm3qaePOMCY"
Output for 7.3.8
string(3) "YUZ" string(10) "6991664374" string(64) "luxNG8wBn88ikQ8zE1DPGBlBzdbsboIBdRKps9tNsO7rDivw5MSHfhoEVpgkaSr7"
Output for 7.3.7
string(3) "DEK" string(10) "6182845391" string(64) "wuJKUYYVHNtKa7yKEAvOqeAJuyw1Vl2Gzfqf5l7J8aeNyePnr6RKNum8GtIVVPfv"
Output for 7.3.6
string(3) "WWB" string(10) "2283719762" string(64) "3AgzrlpKhAsjePdHhOzz3btf5gtXdiG2mtJ0nNlpCnd59hEe6bDsSY8C5W6kz8fe"
Output for 7.3.5
string(3) "DXH" string(10) "5581292323" string(64) "LbRAydBexA9ev2Bb6N2wktlvYWd7JYZhaetN8qmkYcjdYIhj7Anjn4cj3xSjvdC1"
Output for 7.3.4
string(3) "EAW" string(10) "4468611525" string(64) "38447U4gel1SiK6j7K7UhgMM7nHjHqPccswUzunCRKEVZsCRkcMVlvX2eI1BQTSV"
Output for 7.3.3
string(3) "PMP" string(10) "9596171528" string(64) "f4HXU3Fm5YKLSqZb8ZrKVR27g14WmxuewhtxP7h3YG3Jx4YrojiqvLBeiMOBEyhA"
Output for 7.3.2
string(3) "GRU" string(10) "5112361993" string(64) "CjcqWClonfMHxVEP7E4nYFy7YNaCYbocTIQeAZ71neCERJj0ki434ItUqxOTDfm9"
Output for 7.3.1
string(3) "QUF" string(10) "7622177441" string(64) "A0ya5TlEfLJpZrVMHtPvbH51rRKyfZP92Bf4WxhA0uD1TItmWoLp4fy0nBFnXPzj"
Output for 7.3.0
string(3) "MSO" string(10) "1894655241" string(64) "XLQwoFPaEAg6pb4vMIfuoVm2f1D1WkgsFJQ5viPx8D37VLE0y8RMROSFfGHaerT7"
Output for 7.2.34
string(3) "LLT" string(10) "9839327556" string(64) "t8xTbdBQYX5zucqFxymXrSMNdr9AR8YYhrCEXNAEPf99dJneAqps94Rp1MA5bOvB"
Output for 7.2.33
string(3) "GAX" string(10) "9253626381" string(64) "s4Ekc5VOBvQjogMQEaRMEOQSOlr8Ht03mSJ5LRh7ON7oSiSN6VGjcrdJoGX5pJ3U"
Output for 7.2.32
string(3) "BEZ" string(10) "4957814211" string(64) "gqagwvPgAbMDPjgN9v3GAyERqGQa4bCgYAm84jf87GU8LC54GldFHAzOcIjpLAHx"
Output for 7.2.31
string(3) "LKE" string(10) "1973346472" string(64) "vosx64yZs5RIxECWYE8bddqSIO6IGf2WQdhpyWloICUV2YUfGRYjJLOf0QrPU2Hn"
Output for 7.2.30
string(3) "CCN" string(10) "4257445262" string(64) "HNsvidpoY9D437SIcpqnVkYrW0l0soBWrgPApBfpIBei27bGDCy59JTZ4lVaFQsV"
Output for 7.2.29
string(3) "JAA" string(10) "9394746748" string(64) "eE6qNLa2rWDYAnEmaEvezMnJaGtTJxg8E9MXOuTOkQ4grwlGq1qxCNUds9xeVTfS"
Output for 7.2.28
string(3) "TBM" string(10) "3917377939" string(64) "WfjcOKDLhQLYsJs2lEjwNth390ZCCRtusdgcXlHjRPBwf6t5SSXDm1TJdiaAhP8b"
Output for 7.2.27
string(3) "ZGV" string(10) "2351513224" string(64) "f87OGv8of4Iviosds2CaeT8GuE0G1hkmhID8saQPKbF7f6ym8mpwq0AfLUVWPcyX"
Output for 7.2.26
string(3) "LNC" string(10) "8414199354" string(64) "3glhfza2nhyPKYKOwI87jGWVBoQcdYO0AMRbhMbBFY5mPJWxXGwCvHC3WmwAHunQ"
Output for 7.2.25
string(3) "COY" string(10) "3182365412" string(64) "10Nszx12vVh7Q80OWfk5g38te74SL4zfUQZijcNezNpd96nD4mp63vigMSJiVIg6"
Output for 7.2.24
string(3) "MOK" string(10) "3919158467" string(64) "zoNotliRhgVOxSfrhQtyk2Jleepss4jrmwkLfDHJwubXPLxdZRbg0DJZQuH2hrWi"
Output for 7.2.23
string(3) "ODF" string(10) "3312682816" string(64) "jpMFATCfSQd60FXoaMybqDiaJjg9eKfBgh8DRNAGHTtHR7Xfayom5S47H8yqj8nr"
Output for 7.2.22
string(3) "RPB" string(10) "2913761619" string(64) "218jSJDu8qcInp5L38tJG5x5Vhp96GmWYgxn5RjkXDsQtzanwuHZwgrnv3b8uQjE"
Output for 7.2.21
string(3) "QOE" string(10) "9483993978" string(64) "5hHWvgheVBE6BBbPbncRPdSsUju93UHjtGe2iNhkLRrr3eeecHZC4o3aaXewZW4O"
Output for 7.2.20
string(3) "XXC" string(10) "9637931261" string(64) "8pqzJvGGcABbJqmPlrJgxSYYMHlIzOavuG2nsuGCfuan96LnlT0gOlF4wjItrmzQ"
Output for 7.2.19
string(3) "EUC" string(10) "1872532262" string(64) "vPqdB2xSpw8CCtRksLpaVEvd9rvfvRXvSE0Vpc2NZShIkJtA8yTguYbYM5VBltJL"
Output for 7.2.18
string(3) "QUS" string(10) "4218471437" string(64) "GIp6G6lD7oSqCyuJHz6m5GWSZW9Kame7bi6cNuYKsJbhcRZfnDIUDNqchDySV0Rc"
Output for 7.2.17
string(3) "MPX" string(10) "8343525654" string(64) "HibYylVcSi6HW9aesXsjCM5Th96mRC8YfhuUttZ81ocABUPlLiqwQb9SmsRAecUA"
Output for 7.2.16
string(3) "PZQ" string(10) "2939142515" string(64) "kpirFsnssWodCTE0Jy9y7nB85IToleUnqVQArhuYGWmfXncOggxPBa0Y2EW080WN"
Output for 7.2.15
string(3) "VQW" string(10) "9488611861" string(64) "JB3bovnP9rlQcXbfrtx8mu7fsVLqW9Rj11h4rGggq1rDhYBqGdkINHO8iSbGNraV"
Output for 7.2.14
string(3) "RBS" string(10) "3171775611" string(64) "IZKTtE5Va0eGjOQFOu8OTpGY45r9ZrsLksYQ9Qx6Fxi8pr3cygcd0oz13wxqoCgF"
Output for 7.2.13
string(3) "XMN" string(10) "6638285528" string(64) "pZFH10AJ3RqOQeEXfnD3GURXFqoGzxfdZvqousyOvMsktOGmLykX0MhKOf751utV"
Output for 7.2.12
string(3) "PLC" string(10) "5511919275" string(64) "U9JjTWjrolN9HMZBwQqh6hgreEO8FVpE6jxjxFO83Ks5HWwUiiToxqKeUkEvl271"
Output for 7.2.11
string(3) "BXY" string(10) "1829341621" string(64) "ci1Bg5UjoumXdzIc8uwx2YVNKEEEjdJHeW4E7NZkO8MkDgsXeTXzeL0W3fqUNJRi"
Output for 7.2.10
string(3) "EVU" string(10) "1657335324" string(64) "iEGuFVgBfiCCyLhXsfQAUUAB21JaLWbNpk4QGRNbARa7RjmRDNdiTteRtDWaXoUI"
Output for 7.2.9
string(3) "RPH" string(10) "1391824227" string(64) "XRWWM63Hei2aS74lt1VfUO9OI2pBdfkR0GEFZmHRe5mdjZ6Mf10tobKnJtLY3wDT"
Output for 7.2.8
string(3) "IRR" string(10) "2882132486" string(64) "fdTTXvysHhiF6eAN1lQbcSa8aJFxbiLvCKjRAbyXS6bZstZNYqgnLNCgQ79eMNOJ"
Output for 7.2.7
string(3) "NWC" string(10) "4686484819" string(64) "dg89xsKff56cemAMSqHuUSw3sSXWx3wC3ek74MeKI5lJ41R2Vs4Nitpa0J2Rsa9R"
Output for 7.2.6
string(3) "TYC" string(10) "5929823158" string(64) "imgnSQEhw6v8lK8oWqLm2pbka03qgD2GBjrZJ1nmUWMiY4CrqDBtMNGZFUWx5okz"
Output for 7.2.5
string(3) "MNM" string(10) "1483564872" string(64) "KHPCQQlsfOQYjc3t4R1tDbvpn2BMJ1QXpm3B8JrqvXPXo89KEA5UJoSJDk6Sy5sB"
Output for 7.2.4
string(3) "NQE" string(10) "3294855264" string(64) "7sp6ECOFRgHrBhucIhGd7QBt0nfRbG9seKVCmpoHoxvwUZhCbLMrdP0fmBb8mzEV"
Output for 7.2.3
string(3) "ZND" string(10) "6647591762" string(64) "Jly1OwDTdmm9ALpnnrb3QATbD0h07fOmfd0Nvv4mUyQdWNoDmi23v0AxzQZFV8mn"
Output for 7.2.2
string(3) "TPS" string(10) "7179431725" string(64) "6aLKK1S7o20vxKgMtVt59DDPFzvpuMGxonwm9satHYocTMWFC3hmqj7YMzb8Bb7o"
Output for 7.2.1
string(3) "BYM" string(10) "5455728736" string(64) "0dkPGCKKJaV2ukvtYuZmJ8RqztwhU3ldy07EwrptMElUesItspN2dpukyPTLG3QQ"
Output for 7.2.0
string(3) "JME" string(10) "8212565641" string(64) "Rc75P9EU29zOaZsK4mVCRxhpSeFEGxqrxvgygmDqikB5P4IrH2k7CCzb0ZLihIvM"