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-_') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } var_dump(random_str(110)); var_dump(random_str(8, 'abcdefghijklmnopqrstuvwxyz'));
based on TSlF6
Output for 7.2.6
string(110) "jBzUQE5ezaWiXvncZfTL5pGrcm3HV2FltuP_c1novg4JSONWzQc_X09txoqDz-Qukl3wvgtFKmONxrtmEZao1q_sf0KuK53cs_0oRW20TMT6y-" string(8) "jmgqpcds"
Output for 7.2.0
string(110) "Ll2-1j33WLAX6Yq59AO7LA9l2EP_TNDKSbV6LmqK66m8I4fK32Q0Egh_prVEKsNVon_m4NiIeTaxpyk6Wc3ZB65NcMPEiaiwSWnxaTYLTE-Od4" string(8) "slqtjdqf"
Output for 7.1.10
string(110) "WJKmfYKOOQLDE704QZ1AyDvb_PX1CVyQvA439SiwJhGbhwrSJ9gep29k1uQABdk9xhphL1Sp5J_E1DwY_ihXXikMIKk4mzjPfWHqstXwU10GNT" string(8) "clputaas"
Output for 7.1.7
string(110) "tvFMpbhfYZfLsJQlR2BYWZTiENzvFXIB16NMzl45zPWR8rP5r2ALy7nRs7jaTu8z7IlY1OWhTdjXtz_I_aavNo-GOV-n1lYVvzKQNGlLHNZ36p" string(8) "kpkdoynt"
Output for 7.1.6
string(110) "jTfB4SraWdZLhfH5RaPRLhKIiKDd1LzbH38DcP4F1VUTUegMfqvWczWjUJjuF1Wdr_jzrN9lk8M0rjzxAEpRaLEFiyELRopb1df-blmxbi8tKl" string(8) "xmlyoolz"
Output for 7.1.5
string(110) "aRUTnehG53vQHgKH_VazffOQ4ySBFhvtUWA_fPTKrJblfphlCKKWSC4ZvOFa2EcPPoPogwJInj7TAuc-CkLG0bNbjV9DpnLStgniY3FtfWH_13" string(8) "yhqbawsu"
Output for 7.1.4
string(110) "4hEHuGfqQp_S8-0NmaaHn42-osA4iJQshISy0IXONZliVZeyqynDeQDtF4X0oGhI9AaUDmC4h9nSjXgIAGBDEwRBnHilSkr54QW3qoDhgQjE2x" string(8) "wmmgivfc"
Output for 7.1.3
string(110) "be0eIosFSMy7Tc-sh49jDHdZAfuEJaGGy0yDGUN1TrnAszIfOmo9LfAjF2e_1YSkMAkxXyNVI-u70zyt1Gway3zZWHiidJk4rx2W5rjHWH69Nk" string(8) "xavzosob"
Output for 7.1.2
string(110) "l_0r4LsjzPN6k_TO12WGgoGG36TlC6XbcXVYI6h_J2LSKZdRO4B2q1F-aPD1zLJscCISN4dGGLOXvetxemv2jR3UYlrH-MpLZlpf5hZHZyOjno" string(8) "uvostbgt"
Output for 7.1.1
string(110) "VeQImrmB7OhZjnLcs0N2bfcefj7tZlJ2xV1x-bg5sYB2NizSf0okayjaAID1MYN-bjXlIOr-OXVK02ofjDddzcaihWGMsOcZY0rO-_wn6SgrDJ" string(8) "znvsrgzy"
Output for 7.1.0
string(110) "a9LbVZeXnrxvZzXVLwvvepH8YCNFMJfdti8p58kflUBbi4oSCoIFDRZBw8qy6IO-7Gi4HKGtjjI1T9rA-B-7REWrvgBXL8-MjIfm-atFEWMVjU" string(8) "qdllbwst"
Output for 7.0.20
string(110) "x27Vq3bedcKRR5DkJEi9Oe6GXlug46xHeu6EpVPW2KPjNrqBDUSDGWoNJJf-DHpeN6Y1QZ8tK3KSZBeOtBbAw94IG0dlpyFzsTgnECoowScdrd" string(8) "xhtjatih"
Output for 7.0.19
string(110) "Zhm1dlyrnO8tTzQOB2kEPaIZmH-tQUdDKQPlM7tmNPgalUt268X3MR-I8gijr9JaDMmNz4LujQNrsrsDfqR7QmvQptp78HHGszFy4Uz2x5cLUh" string(8) "pugpxakc"
Output for 7.0.18
string(110) "2PQxwLlc37058MXjSE1JeQ2ZXyfvy0aqz7uStSAYdn2akxPCMNyxvHueBeD3HgvUttZrl11m2ANQPdovfCTvigLab5f5pFjUm3W62_MFCpSexI" string(8) "ejfhgesv"
Output for 7.0.17
string(110) "QN69L7Upp1atfBv9ySFtvwFhb9acYkOECO74BnjH2BeGVWjfNnj4JmO4qAnqJqbSQRjGV8FtclPBfati8wR1Kbs3lKqJ-KsK5EfxV-HKAvNqKS" string(8) "yeaesuwl"
Output for 7.0.16
string(110) "o8D72bksNuIvCaMQ68kjdm8zzZhNZypbGSBN_LmMsLTvZftuF8uGuteEZMcRrUM7DlxYWEhteMWR-rRidipZ1ymnhZpDtA8RHIesWhZ0No-XI7" string(8) "twaaidxj"
Output for 7.0.15
string(110) "4yKPPVh7TKzscnIHZ_1j5ueKuCw4AHPh7_g0c8UD4tK7_Wtt9ND29wAOLEZG7H-7lEZ5yLXwYsGdAUSYcBUy7yxcAQZnr8kWhZtI7dj_3ql7C4" string(8) "tyziztii"
Output for 7.0.14
string(110) "wzh23krCAFipkhTY22PmU4xwxutvQtacypJDz577STR2zoHvlgkvxhlaGH--HtKzmazA8Gn6sFd6b8EqddXd9PFxTcRMRcFE4wQbDsJ1W0SGLs" string(8) "yosxaqir"
Output for 7.0.13
string(110) "q7m9GouB_pB9eygX-99ysjFaQ_I2pEFNdQCSF1kWoQ9V-yQvSB_-je8gHg93Wfnpe9lPGWIhdm_me8x_m_HTCORLCCPXWsX7obHxorr7pT1zFg" string(8) "habrofud"
Output for 7.0.12
string(110) "lhtyywudJWg0Adm5vKxfjm7rvHwdfTVig7nvngB-a2hYHQgeLw2dO7ZKPQqBoS0kArHrGUbaV6sZs4ZytyyilViC9bjskA6aEQVo_BmnsoHISa" string(8) "iezuhhot"
Output for 7.0.11
string(110) "iPP40I45Q0xn0oRgjAAZ_zIFeavJ0Lg8W_0ChTPFYJaCKJScxPE2h2JL-oPl0kDfdR05YI0rfI6XuqXualXFj6-YyimFLnF2N5Jiyljc0GLEXb" string(8) "wwadciem"
Output for 7.0.10
string(110) "gmY2zD290pE9JpzfRTlsnJHxZAvmrHqg_pHOPdkDBbM_iIcvUF-q65KZ64znaYqbNrxbvtW2i3t9eHrmwNkzbl4qY3BIusiy5xdJQ2-oRBC48N" string(8) "odsurnfn"
Output for 7.0.9
string(110) "smwzXJYP00T1Ccx7q2q-zqDwnUp2P8lx1VkB0qYaetAGtT2LIYSB_76WR7KOaMl2udoyrgqV_l-XT7LpHP6cT1F7oKPqW7NNLTmEdFf3ez_thh" string(8) "dpjzaifk"
Output for 7.0.8
string(110) "itBX6NsWWgfniwsMJ-0nktlmX2KHyzddUyQYjvazg_wIuN026ctYT_fzzq6ozXSpojIITANmfNWpfJjmoP2vSlJk7MXWyN5J4W7qOjqjqwrkql" string(8) "jwahsdgk"
Output for 7.0.7
string(110) "5pt15YncEPmvY9thXHYOh5HVamCYVKgmakooKdPe1s2wWOgQDVLhl4OiHRsldhtMXZRvzLwyLNWBpXi7FdncId12i7FAEafkv1YQjIt-KN6_qY" string(8) "nlxsfoad"
Output for 7.0.6
string(110) "LHr1JlAUpyz5u6S1sL2ZfSqnwCyqdge5rdky1WgMtNPutoUFuDlDLR3L2FrGTci5vy1aoZTvkFf7u5svNlu72yHDCcU92KL35LI-TTt2Bl57T7" string(8) "dugpgowh"
Output for 7.0.5
string(110) "V27iL61ju6OcVfb6u733GnVajJXROzppI3QDtGnjEkn0tXFrfXF_oBgCep9WGijksrtifETxXFLRw6ooDwVgCIJeg5GIafXW-59q3NTsLE9lUi" string(8) "wvfvtqni"
Output for 7.0.4
string(110) "2s70pY_wOJ0smRILEC4tMHLkhqpzwC-D446zCXiW3Q0YZJyodq9YB_iOEvkvkX1xmARZxZEqQhohmDhxU4hJBovBziypUDfGKn64acrDptW__E" string(8) "xcjkoxdh"
Output for 7.0.3
string(110) "9aItyeS4kgqOwZk7XMn3tXgWBqF1jHp59ft3QV1vO47SdAssxFhzS4pIblAANmHlAfe03Y1-cow5ySoDQMiJP5IfdhSsuWyUgpZNBbXGbjRsgH" string(8) "nrjcgxum"
Output for 7.0.2
string(110) "MXousHb7QiZlquqsZ6w8e7XRRe7lN-S-426gHDWHLVqqepL-EZ-Qikzb351SBLghHWO7s-grLa6dQrt82p8Eg00_mR9T35hHFX1ugcumSSQBfZ" string(8) "msyjtsky"
Output for 7.0.1
string(110) "8sBCE7KXJX5yOalRMSw1bCrQ1sHMyHK0AgwwHm1V7wBiHywbw-OT68mRA5Avyfj0wuGEn8_jdS_VtP_OWTYht6yFtvFKnYbHINoZ3AtmfZuax-" string(8) "gsnunshj"
Output for 7.0.0
string(110) "FWRDgd2A6Yrd3tr3fedWko7t0iyuOij_jWzgx4LdQ_olEUOLk5rlP7sfnxsLmHXmo-vhML89gtpMvqg1Vvi340abqmmEKMksEcIgiTQLjE5GS2" string(8) "xpwueqaz"
Output for hhvm-3.15.4
string(110) "Y_PII70iXTF8Jtpw08Y40WtwZxNEvuZhX79u0OgLqE_nP7arDT4LzVVXBkJne7FfI4o4c58ZMEqXA9vJiXZlNWVIprfVTxee1LRPoazmc5T9PS" string(8) "fqonrhih"
Output for 5.6.0 - 5.6.30
Fatal error: Call to undefined function random_int() in /in/uDEUa on line 20
Process exited with code 255.