The number of different lines I can get using a random random PHP chain

I am currently running a URL abbreviation website http://nn.pe and using a 6 char random hash with this code,

$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; return substr(str_shuffle($charset), 0, 6); 

I was wondering how many different lines exist with these characters and integers?

You don’t have to be precise, only within a million, I think.

+4
source share
5 answers

A warning

I just looked it up in PHP 5.3.8 source. php_rand() . This is the equivalent of C rand() . I would be very careful with str_shuffle !! It (usually) will give you as many features as getrandmax() outputs, which can be 32,768 on Windows.

On most systems, you will have a theoretical maximum of 2.1 billion.

+3
source

62^6 = 56,800,235,584

Inside [a-zA-Z0-9], there are 62 hash character combinations with 6 characters.

+3
source

If the shuffle is the correct shuffle, such as Fisher Yates, you have (26 * 2 + 10)! / (26 * 2 + 10-6)! = 62! / 56! = 44,261,653,680 Opportunities because we have no replacement.

+3
source

Fifty six billion eight hundred million.

For each of the given positions in the hash, you have 26 + 26 + 10 options. This gives you 62 ^ 6 possible lines. 62 ^ 6 = 56 800 235 584.

+1
source

62^6 = 56,800,235,584 .

However, you must have conflict control.

0
source

Source: https://habr.com/ru/post/1388771/


All Articles