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) * * per https://stackoverflow.com/a/31107425 */ function get_random_string($length = 16, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } // Tests. echo 'Test 01: ' . get_random_string() . "\n"; echo 'Test 02: ' . get_random_string(2) . "\n"; echo 'Test 03: ' . get_random_string(32) . "\n"; echo 'Test 04: ' . get_random_string(16, '1234567') . "\n"; echo 'Test 05: ' . get_random_string(16, '123abcABC') . "\n"; echo 'Test 06: ' . get_random_string(16, 'ABC') . "\n"; echo 'Test 07: ' . get_random_string(16, '10') . "\n";
based on b5lXg
Output for 7.3.0beta2
Test 01: cGc0285BaIZeXBlQ Test 02: vY Test 03: BAK4uyaAt0yZN7MVt8QfKw0WJ6UuWaHo Test 04: 6461312742237724 Test 05: aBBbcab3c122cbbb Test 06: BCBCCBBCBCACCCBC Test 07: 0001011000001010
Output for 7.3.0beta1
Test 01: prp29AUusedBCvPF Test 02: 2i Test 03: sDGugPZxncep5j3N1jf5xA7YUI4sFUnQ Test 04: 3462471775244626 Test 05: a2aC23Bca22A1abB Test 06: ABACCCBBBBCCBCAB Test 07: 0011111100011001
Output for 7.3.0alpha4
Test 01: pBOCTu2KIQG01afe Test 02: JG Test 03: PgW0MvaGAJfRs1BWqoPKBR20QFjJVggp Test 04: 1345746532662322 Test 05: 33cBCcc1acbB23Cc Test 06: ACACCBBACABAACBB Test 07: 1101110010100011
Output for 7.3.0alpha3
Test 01: vIuEwWUdKlCSGn16 Test 02: gn Test 03: gWOUQRZj1e5GSe3pF7C4y5IRs0hIgjZ8 Test 04: 4731665224174636 Test 05: C21bc13CBC1bBAaa Test 06: BBAABBCAAAACBCAB Test 07: 1111110111010101
Output for 7.3.0alpha2
Test 01: nyZNZVTZihYq9DL1 Test 02: np Test 03: yFVo6NfuoYI5LnCpBwRFnkCPJJClUmmx Test 04: 2535565742727115 Test 05: b2a33CCCc1aC2aac Test 06: BBCACBBBBBABBBBB Test 07: 0001101011111101
Output for 7.3.0alpha1
Test 01: t6LyIQJwGn2QkO6W Test 02: aX Test 03: lKFCtwzGuEtWm7FpOhOCtw86obHR5w86 Test 04: 7231367574113336 Test 05: aABc2AbbCB33a133 Test 06: BABBBCCBBCACCABA Test 07: 1001101011000010
Output for 7.2.9
Test 01: 29KBp7vQsCLseJyI Test 02: dz Test 03: BGmGXmsSK3FX7M21qR75tuJcZkV9jnDR Test 04: 5711462174412423 Test 05: 311acACB2cbcCBca Test 06: ABCCBCBCCBACCCCA Test 07: 0001000111101000
Output for 7.2.8
Test 01: b0YZHQjsYe7bIV8P Test 02: B0 Test 03: 1wnfOzacgvyWKcPdWS03qe0KYOOK1raF Test 04: 6737273336731466 Test 05: CB1BAB22bccA1bab Test 06: BBBABCABCABCBABB Test 07: 1110101101000000
Output for 7.2.7
Test 01: r0dqNWBPyVDxQ2lL Test 02: Pl Test 03: fapTmk2rTaLoXlYt6bYUU0Y6z82tCSVu Test 04: 7411457115232465 Test 05: bcBbcAABCbaB1C2A Test 06: CCAABCBABCBACBAC Test 07: 1111110111010110
Output for 7.2.6
Test 01: bTDjjwxQIvkToaM1 Test 02: 6J Test 03: cNrDo3JWgNrXX2pNCrAnNKmEqJcsiR3p Test 04: 6233652436365552 Test 05: cA12B32cAa2Cac1B Test 06: AABCCAAABAABCACB Test 07: 0111101001000000
Output for 7.2.5
Test 01: N6H1tszzFEJDKWd5 Test 02: JF Test 03: kdhrqSFrAOwDq4888NksTQm8rNRzHQs7 Test 04: 1166517557526672 Test 05: 32a3cBABcC2CabCA Test 06: AACCACBABABABBBA Test 07: 1000111010000111
Output for 7.2.4
Test 01: lkUbJoQLt3CKkBgF Test 02: Mu Test 03: j64ptll0OdA4slYOpThTBEasNZckKo7X Test 04: 7532362556255366 Test 05: 31a3AB3cBa3aCaA1 Test 06: BBACACCABBAAABCC Test 07: 0010100001110111
Output for 7.2.3
Test 01: n49C7OOiZUH4aHhh Test 02: nJ Test 03: 3lv11JI5CHa4HLLNeE43QVjhV4vyABo3 Test 04: 4417342433377272 Test 05: bBcacbAcCb1AAbaA Test 06: BACBAACBBCBCABBB Test 07: 0101100001000101
Output for 7.2.2
Test 01: lS47ju9DqQhW0aQa Test 02: Oj Test 03: 5k1ap51slgBbCRxoq2mjLweXroRO4H9E Test 04: 7722742366464766 Test 05: 2C23BBbb12Bc3aba Test 06: CCAABCAABBAAACBA Test 07: 0101000111101011
Output for 7.2.1
Test 01: qD8usrGVcJcARF3B Test 02: Pl Test 03: hseT6yIFrKiglWKoXQaeIY8vCJF1JTYK Test 04: 2744256454541662 Test 05: CAb1BcB2ACA212CB Test 06: BBACCCCBCCABAAAA Test 07: 0010101110011111
Output for 7.2.0
Test 01: 3EnUNXVZCjFiP4H9 Test 02: to Test 03: 617rB7jjMopxSDvdRETS7SFMq7ygIyv5 Test 04: 5643465527732754 Test 05: aBBCB12Bb1A2BBab Test 06: ACABACBBABCABACB Test 07: 0100011100001110
Output for 7.1.21
Test 01: zigkOSQfcFyyCALp Test 02: xF Test 03: XzfHaGTUqHtEu8D0FbbmTNo69q3Et5Iw Test 04: 3443745656565542 Test 05: 32AaA3cCaAaAAa23 Test 06: CCCAAABAACCCACAA Test 07: 1100110101111011
Output for 7.1.20
Test 01: Mkuoi6ocJHyrCmCt Test 02: 1B Test 03: D6zv2B238KX9Tf6xuvfYem3lWWdW3Pu5 Test 04: 3253172415323366 Test 05: c12BBBbcCaaA1aCC Test 06: BBABBACACBBACCCC Test 07: 1101001001001001
Output for 7.1.19
Test 01: qMg1jth48myfx2qX Test 02: 5G Test 03: 2siP3cupRE9hHEtL8UUbSh3wG1ryDQpj Test 04: 3276347733153146 Test 05: 33a3BAB2bbA1BCb2 Test 06: AABBBACAABABCBBA Test 07: 1100001001010010
Output for 7.1.18
Test 01: C0NyEBAsS0ECC2Yl Test 02: VO Test 03: CqafQDS0U00Dq9Y6MibUNEsjpUoyiulG Test 04: 2117746346432714 Test 05: CaCAb2aaCbB221a1 Test 06: CBABCBABABBCABCB Test 07: 1000011000110111
Output for 7.1.17
Test 01: dcbhNDpb6CXiWLc8 Test 02: xW Test 03: y2NHqwCytHS3nRvgK63wL24y08BD6Z4q Test 04: 3235742146133572 Test 05: bABaaaB1baccACCB Test 06: BAABBABACABAABCB Test 07: 0100010111011000
Output for 7.1.16
Test 01: hTrVJOMNLNzk5OP4 Test 02: su Test 03: CEtYA2vBIera6Dcrq5lOumoaRWarpC1d Test 04: 2262246473764475 Test 05: b2cA3aaaC3a1aaBA Test 06: BCAACBAAACCCACBC Test 07: 1001100010010000
Output for 7.1.15
Test 01: IzCeAfWCgjp3ERd6 Test 02: 9M Test 03: dN6r6S25Ejk7YrzMjXdkdOsf0UJRWDw0 Test 04: 5316543326655452 Test 05: 12AC2bCbB331a22B Test 06: AABCBCACCACBABAB Test 07: 1110001001010000
Output for 7.1.14
Test 01: cCvHSvFe2yF64TFy Test 02: bS Test 03: tVn7uy9ZnZzELVfsA7oVm1kEiTqkys80 Test 04: 6121764633767445 Test 05: 1bcbC1bacb23bBba Test 06: AACCBBABBCCCBBBB Test 07: 1011011101000111
Output for 7.1.13
Test 01: vj9g41LmQyyGvs2v Test 02: Aw Test 03: yoBMstYnLrWqxln1PNu4BPEbbNbu6XsS Test 04: 4663335671671337 Test 05: AaBAa313bC2cCcCb Test 06: BCBAABACBAACACAB Test 07: 1111001001101111
Output for 7.1.12
Test 01: UTBOKiCCvqeROFqM Test 02: gs Test 03: GLqkUY8VWC85zzRjwDvJAr9OOpVu1sLO Test 04: 3344656663365522 Test 05: 322aCbAB1cac22Ca Test 06: BCCACCBAACCCAACC Test 07: 1101001101011110
Output for 7.1.11
Test 01: aTMBrNGBRe4U9npX Test 02: 5b Test 03: EkYyHAzhqSc5TPVGoXqRe3uIn9ijHQYx Test 04: 5357116241437277 Test 05: 231cA22abBAc3a3a Test 06: BACBCCCBABACCAAB Test 07: 1111001110110000
Output for 7.1.10
Test 01: 4SiMUIEmAJo8lsaF Test 02: Tt Test 03: BBa13H8MiY7I9OToeiGg6mCkUNVDfu3Z Test 04: 1145552476767622 Test 05: 1c1Ac3bC23CCACaa Test 06: ABCBBAABCAACACAB Test 07: 0110101101010001
Output for 7.1.9
Test 01: pJlS2tsXonCmq1CZ Test 02: WP Test 03: oDuyG304YqNvNula9nGtmlzGLalFjACp Test 04: 4562462274775154 Test 05: C3AcCbb21a3b1cbB Test 06: CCCCCABCCCABCBAA Test 07: 0101100001111011
Output for 7.1.8
Test 01: 9eWEZLk6ypTwoVdF Test 02: EA Test 03: f7SbYy43sJyareraJyg6bCAOGXc8IWxX Test 04: 7626362217362152 Test 05: cBA11BABc3AA3b2A Test 06: ABCACACCACBBACCB Test 07: 1010110011011111
Output for 7.1.7
Test 01: TysPDUqz28AWXCfr Test 02: AM Test 03: Z9cuiFZPMTr33e7eB0juOF9cr5JQ8FwY Test 04: 3656622724365272 Test 05: B1aaA3212C21a1A3 Test 06: AABBACBBAAAACBAA Test 07: 1100100010001001
Output for 7.1.6
Test 01: wUCkqHysrPrZqFtE Test 02: Dp Test 03: P8RVO2IW3gUwph1CaQNXyjeolA3NhTaD Test 04: 1152621444545336 Test 05: 3ABaCaABC3BACACB Test 06: BCCCABCAAAABBABB Test 07: 0100100110010100
Output for 7.1.5
Test 01: 79t9MzG8rOzJuau1 Test 02: sv Test 03: Lk5YHIEAvVuUB0wSGwk31OE3txYnw10z Test 04: 5657315315675146 Test 05: B2a2b3B3CAbB2c1b Test 06: CCCCCBAABACAABCC Test 07: 1111011001000001
Output for 7.1.4
Test 01: LDZRNym1BaCzAToG Test 02: km Test 03: pPvRPGNOgK1hG8M3TSicpiRJLKxTXyNR Test 04: 6745537121153414 Test 05: b1BCAAbCcb3CCCAa Test 06: CCABCACCACCCAACA Test 07: 0000110110011100
Output for 7.1.3
Test 01: 8LUTpDIYsKQHThAo Test 02: CD Test 03: zK94pRzojBnwd4r8ahLEyVYZCSB3wJtu Test 04: 7567543621354741 Test 05: 1Cc2ACC12bc3baaB Test 06: BBABBBABCBCCACCC Test 07: 1111111110110001
Output for 7.1.2
Test 01: AG9M3fbGSaFCBB3z Test 02: jJ Test 03: hKI4iSP4x7orDfnozv6X0Xo9uPqtkJcz Test 04: 6764544337746174 Test 05: 21cAAA2aA1abccbC Test 06: AAABCBCBAABACBBA Test 07: 0010100110111011
Output for 7.1.1
Test 01: iYxUEqFRjNigtbCT Test 02: 97 Test 03: 8SUowe82sCAx7ZhQbZaBwQh7zTVhp16R Test 04: 3711342322554163 Test 05: 313aC1C1bcAbB111 Test 06: BBACBCBBCBABBCAB Test 07: 1110001101101110
Output for 7.1.0
Test 01: Irqqg21JfTnW7Lwi Test 02: 2C Test 03: CXuwJOTb1ofMOBATKc58PSo7m2QCCd3l Test 04: 6565726555347626 Test 05: 2cab1Ac2a11BBB1C Test 06: AAABAAACCCBABAAC Test 07: 1001110011010011
Output for 7.0.31
Test 01: tX5evC4PudUc7Z9D Test 02: ja Test 03: R0LyhEgWBYL1NcIHcqi7hvJPOyJPBlGs Test 04: 2146252264622171 Test 05: a3CB1Acba21BBC3a Test 06: BCABCBCCBBAAAACA Test 07: 1011100100011001
Output for 7.0.30
Test 01: 6GAdDPh8yDwUIBpa Test 02: 2z Test 03: tiJZqtvzw7P2pqquQUpnXQcF7HO4A5aS Test 04: 6555121576267563 Test 05: aAacC11a3B1baaBB Test 06: ACBCABAABCABBACB Test 07: 1010000101101001
Output for 7.0.28
Test 01: FnSglHp8eFL3VoG4 Test 02: 1c Test 03: X60siVXjj8qLtiXXqO5DtUXTNwFOPf1Q Test 04: 3551422416264262 Test 05: AAa232ABcCA1C32B Test 06: BCCBAAAAAABBACAA Test 07: 0001001111001010
Output for hhvm-3.22.0
Test 01: qLUKOpJbSVPwsVwv Test 02: XP Test 03: UC6ZZLr2Tr66Do2oABscF9qqsaZdk2Ys Test 04: 6547646324141514 Test 05: 2Cc33b3aaC1b11CC Test 06: CACBCBCBCABBAAAA Test 07: 1011111011010111
Output for hhvm-3.21.3
Test 01: X8J747fIRhmk7hJL Test 02: Kw Test 03: Jqwlm4cnOtAZsMYZ9jHD96oYKPVaNwY9 Test 04: 5343376664473663 Test 05: aAB3cCCb12Cc31Ac Test 06: CACABCBAABAABACC Test 07: 1110010111001111
Output for hhvm-3.18.5
Test 01: I7qms3X6abz46fiV Test 02: Mf Test 03: iTG6yuZZdZWcUJyBoTHeigkwkMqyqHA6 Test 04: 7764324777453124 Test 05: c1caBaBB332ABbb3 Test 06: ACCCCACABBBCAACB Test 07: 0111001111000010
Output for 5.6.30
Fatal error: Call to undefined function random_int() in /in/U0UDe on line 14
Process exited with code 255.