3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.= "0123456789"; for($i=0;$i<$length;$i++){ $token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))]; } return $token; } echo getToken(6);
Output for 7.1.0
KGLWUJ
Output for 7.0.14
0SPE1V
Output for 7.0.13
M98HWJ
Output for 7.0.12
QR0P4I
Output for 7.0.11
D0HHKS
Output for 7.0.10
90YJ9G
Output for 7.0.9
B1IPZG
Output for 7.0.8
L8B60T
Output for 7.0.7
1JBQQ7
Output for 7.0.6
9Q6FH1
Output for 7.0.5
6J8O5N
Output for 7.0.4
PMCSND
Output for 7.0.3
MY73IP
Output for 7.0.2
Z3VKLF
Output for 7.0.1
PHHIS2
Output for 7.0.0
2ND98C
Output for 5.6.29
VS6GMC
Output for 5.6.28
CH3AEM
Output for 5.6.27
2PEB35
Output for 5.6.26
A2Q4R1
Output for 5.6.25
RWZCDJ
Output for 5.6.24
ZX3YDJ
Output for 5.6.23
AAY1HK
Output for 5.6.22
1AVOWE
Output for 5.6.21
UNG4TE
Output for 5.6.20
9RMPYO
Output for 5.6.19
XKQ6ZM
Output for 5.6.18
QPMKYB
Output for 5.6.17
AFLKNO
Output for 5.6.16
AHIQWW
Output for 5.6.15
APQVFG
Output for 5.6.14
WE0NAY
Output for 5.6.13
CWM5YQ
Output for 5.6.12
LQGX7Q
Output for 5.6.11
9MFABL
Output for 5.6.10
69NGZ8
Output for 5.6.9
7PFJID
Output for 5.6.8
D1DT0G
Output for 5.6.7
38I9W4
Output for 5.6.6
308KM3
Output for 5.6.5
U88F5X
Output for 5.6.4
VUOQKN
Output for 5.6.3
UEVQ65
Output for 5.6.2
VLSKV1
Output for 5.6.1
5RENKW
Output for 5.6.0
0F0X7X
Output for 5.5.38
T6C9KH
Output for 5.5.37
HTLBST
Output for 5.5.36
KF7EW9
Output for 5.5.35
OBI7LH
Output for 5.5.34
HQ3YJE
Output for 5.5.33
MFU1UK
Output for 5.5.32
J8BM7T
Output for 5.5.31
YMUAK6
Output for 5.5.30
GS3GMR
Output for 5.5.29
FSRMCM
Output for 5.5.28
ZRSE96
Output for 5.5.27
GQ4QCN
Output for 5.5.26
J9MXSJ
Output for 5.5.25
XTH5HR
Output for 5.5.24
OSKXM6
Output for 5.5.23
IBE76X
Output for 5.5.22
9C5A2Z
Output for 5.5.21
831JHP
Output for 5.5.20
UF8LRH
Output for 5.5.19
E94ZIJ
Output for 5.5.18
8DNTQI
Output for 5.5.16
KDFV1F
Output for 5.5.15
ZJKL3L
Output for 5.5.14
IATS1P
Output for 5.5.13
PYT94Y
Output for 5.5.12
9F6O4S
Output for 5.5.11
USVTCZ
Output for 5.5.10
O5NLHK
Output for 5.5.9
LDSI5U
Output for 5.5.8
HKN4BE
Output for 5.5.7
YQDK4M
Output for 5.5.6
PN0S55
Output for 5.5.5
YPQDXU
Output for 5.5.4
MSHARQ
Output for 5.5.3
3DER2J
Output for 5.5.2
MXJW2S
Output for 5.5.1
JCXFEH
Output for 5.5.0
I7TMNH
Output for 5.4.45
6LVSI3
Output for 5.4.44
13CTLX
Output for 5.4.43
T7N6EQ
Output for 5.4.42
RKUY12
Output for 5.4.41
XB6KUR
Output for 5.4.40
UI3M4M
Output for 5.4.39
P9GAFI
Output for 5.4.38
1FQ55Y
Output for 5.4.37
AVH7B8
Output for 5.4.36
DXVZM8
Output for 5.4.35
NGZLIW
Output for 5.4.34
QINYNR
Output for 5.4.32
JPZC2T
Output for 5.4.31
40FQC5
Output for 5.4.30
R67RBM
Output for 5.4.29
CD02WU
Output for 5.4.28
61BWU9
Output for 5.4.27
5IF50A
Output for 5.4.26
Z3Z8JZ
Output for 5.4.25
GWF8L8
Output for 5.4.24
LN35GE
Output for 5.4.23
D24NBK
Output for 5.4.22
HLZ6I6
Output for 5.4.21
YMI4HM
Output for 5.4.20
DHCFIS
Output for 5.4.19
V8EWPY
Output for 5.4.18
RTPZIF
Output for 5.4.17
943FTW
Output for 5.4.16
89LTV7
Output for 5.4.15
YYON29
Output for 5.0.0 - 5.4.14
Fatal error: Call to undefined function openssl_random_pseudo_bytes() in /in/0jufo 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/0jufo on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: openssl_random_pseudo_bytes() in /in/0jufo 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/0jufo on line 10