3v4l.org

run code in 300+ PHP versions simultaneously
<?php function crypto_rand_secure($min, $max) { $range = $max - $min; if ($range < 0) return $min; // not so random... $log = log($range, 2); $bytes = (int) ($log / 8) + 1; // length in bytes $bits = (int) $log + 1; // length in bits $filter = (int) (1 << $bits) - 1; // set all lower bits to 1 do { $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); $rnd = $rnd & $filter; // discard irrelevant bits } while ($rnd >= $range); return $min + $rnd; } function getToken($length){ $token = ""; $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz"; $codeAlphabet.= "0123456789"; for($i=0;$i<$length;$i++){ $token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))]; } return $token; } echo getToken(6);
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught Error: Call to undefined function openssl_random_pseudo_bytes() in /in/Z3CnY:10 Stack trace: #0 /in/Z3CnY(22): crypto_rand_secure(0, 62) #1 /in/Z3CnY(27): getToken(6) #2 {main} thrown in /in/Z3CnY on line 10
Process exited with code 255.
Output for 7.2.0
OrCYcV
Output for 7.1.7
JxIMTK
Output for 7.1.6
34eCOo
Output for 7.1.5
xy35gT
Output for 7.1.0
V4vIhq
Output for 7.0.20
ytRLvv
Output for 7.0.14
hi52CG
Output for 7.0.7
zW3ZG4
Output for 7.0.6
qqB6r3
Output for 7.0.5
BjhwII
Output for 7.0.4
bqmAct
Output for 7.0.3
IMhEgp
Output for 7.0.2
hUYK1X
Output for 7.0.1
tP1puu
Output for 7.0.0
vCfVsy
Output for 5.6.28
tp4ktC
Output for 5.6.22
rc2pgO
Output for 5.6.21
oGrrSx
Output for 5.6.20
z9DoNc
Output for 5.6.19
6IRUNZ
Output for 5.6.18
3hdCX7
Output for 5.6.17
VKTZdd
Output for 5.6.16
jAEqao
Output for 5.6.15
WeU8xW
Output for 5.6.14
TxmeJf
Output for 5.6.13
LIVqP3
Output for 5.6.12
30Tqm1
Output for 5.6.11
32d64h
Output for 5.6.10
vpmmZw
Output for 5.6.9
rDz0eB
Output for 5.6.8
jHBxd2
Output for 5.6.7
vdtM9R
Output for 5.6.6
vxpQeu
Output for 5.6.5
pTbsxg
Output for 5.6.4
Gx1fyr
Output for 5.6.3
rIKJeG
Output for 5.6.2
pM2sLQ
Output for 5.6.1
t0eCmR
Output for 5.6.0
T2zC75
Output for 5.5.36
sts5Na
Output for 5.5.35
LJ2trG
Output for 5.5.34
ChhUVK
Output for 5.5.33
wZPcUd
Output for 5.5.32
eP8IOl
Output for 5.5.31
DiPbo6
Output for 5.5.30
QqCkBB
Output for 5.5.29
pre092
Output for 5.5.28
YsRxZf
Output for 5.5.27
Utzpbp
Output for 5.5.26
aGNMEi
Output for 5.5.25
V5lLO4
Output for 5.5.24
gcBeMZ
Output for 5.5.23
mP304U
Output for 5.5.22
7eHega
Output for 5.5.21
x2gSdw
Output for 5.5.20
XZI9fi
Output for 5.5.19
Enp8oB
Output for 5.5.18
wqw3Qt
Output for 5.5.16
9Fz0UZ
Output for 5.5.15
uWkueP
Output for 5.5.14
wkI7Iw
Output for 5.5.13
pVCGJ1
Output for 5.5.12
ioF83J
Output for 5.5.11
Elg5fZ
Output for 5.5.10
gN3rDn
Output for 5.5.9
jQXKfj
Output for 5.5.8
sRGPpa
Output for 5.5.7
B9nm9A
Output for 5.5.6
ibXc8K
Output for 5.5.5
rItPk1
Output for 5.5.4
wy9y2E
Output for 5.5.3
scr8sR
Output for 5.5.2
5JujmB
Output for 5.5.1
uVkPm3
Output for 5.5.0
vziHvB
Output for 5.4.45
QKxMIS
Output for 5.4.44
qrtpKR
Output for 5.4.43
938i9D
Output for 5.4.42
CA7Vzi
Output for 5.4.41
27qoNH
Output for 5.4.40
rIEMb9
Output for 5.4.39
SUyivM
Output for 5.4.38
fdV8gV
Output for 5.4.37
MXDo09
Output for 5.4.36
2wzTqp
Output for 5.4.35
1ho7W3
Output for 5.4.34
FL5aCK
Output for 5.4.32
OByS82
Output for 5.4.31
Knrxp0
Output for 5.4.30
PS67N4
Output for 5.4.29
VE6zYc
Output for 5.4.28
a6Jwph
Output for 5.4.27
ZdeesR
Output for 5.4.26
EQkcMc
Output for 5.4.25
DEivwQ
Output for 5.4.24
FuzPQc
Output for 5.4.23
Eh7ocA
Output for 5.4.22
CC4uyU
Output for 5.4.21
oMMcra
Output for 5.4.20
ZBgQQc
Output for 5.4.19
qj118R
Output for 5.4.18
Q8lrzs
Output for 5.4.17
s6glHR
Output for 5.4.16
DnalnB
Output for 5.4.15
DGlvlg
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.14
Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/Z3CnY on line 10
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: openssl_random_pseudo_bytes() in /in/Z3CnY on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: openssl_random_pseudo_bytes() in /in/Z3CnY on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: openssl_random_pseudo_bytes() in /in/Z3CnY on line 10

preferences:
281.7 ms | 401 KiB | 344 Q