I currently run a URL shortening website called http://nn.pe and use a 6 char random hash with this code,
$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
return substr(str_shuffle($charset), 0, 6);
I was wondering how many different strings are there using those characters and integers?
You don't need to be exact, just within a million I guess.
I just looked it up in the PHP 5.3.8 source. php_rand()
is used. This is the C equivalent of rand()
. I'd be very careful with str_shuffle
!! It will (usually) give you as many possibilities as getrandmax()
outputs, which can be 32,768 on Windows.
On most systems you'll have a theoretical maximum of 2.1 billion though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With