1
\$\begingroup\$

This will go through and create every possible permutation of a username with a length of between 4 and 255 characters.

import itertools
# creating file
f = open('usernames.txt', 'w')
# setting character possibilities
chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
# setting lengths
min_length, max_length = 4, 255 
# generate every possible combination
for n in range(min_length, max_length+1):
 for xs in itertools.product(chrs, repeat=n):
 print(''.join(xs))

I am trying to calculate the amount of characters so that I can estimate disk space used. This is my code to count each character. I am looping through each amount of iterations and multiplying it by the number in the range. Can you please double check to make sure that I am correctly looping so that my count is correct?

parent = 62
# setting lengths
min_length, max_length = 4, 255 
iterations = []
character_count = []
# generate every possible combination
for i in range(min_length, max_length+1):
 iteration = parent ** i
 iterations.append(iteration)
for c in iterations:
 for i in range(min_length, max_length+1):
 characters = c * i
 character_count.append(characters)
print(sum(character_count))

I'm not a mathematician, so I'm just hoping I do it right.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Apr 29, 2015 at 6:08
\$\endgroup\$
2
  • \$\begingroup\$ The total number of characters is sum(len_ * (62 ** len_) for len_ in range(4, 256)), which is... huge (2.97e459!) and also a factor of 128 away from your answer. \$\endgroup\$ Commented Apr 29, 2015 at 9:25
  • \$\begingroup\$ If you want to see the whole number written out: wolframalpha.com/input/?i=sum+j%2862%5Ej%29%2C+j%3D4+to+255 \$\endgroup\$ Commented Apr 29, 2015 at 10:51

1 Answer 1

3
\$\begingroup\$

I may be missing something but it looks as if you should have a quick (or longer) look at the maths:

... create every possible permutation of a username with a length of between 4 and 255 characters

For a length 4 name there are 4 slots, each with 62 possible values. There are thus \$ 62^4 = 14,776,336 \$ possible names.

For length 128, there are \$ 62^{128} \approx 2.6677 ×ばつ 10^{229} \$ possible names.

For length 255, there are \$ 62^{255} \approx 1.1478 ×ばつ 10^{457} \$ possible names.

For comparison, an estimate of the number of atoms in the universe is between \$ 10^{78} \$ and \$ 10^{82} \$.

Gareth Rees
50.1k3 gold badges130 silver badges210 bronze badges
answered Apr 29, 2015 at 8:21
\$\endgroup\$
2
  • \$\begingroup\$ For another context, my computer takes ~4s to generate the 14,776,336 names of length 4. Assuming a constant time per name (likely an underestimate as the names get longer) it would take ~10**445 years to process all of them... \$\endgroup\$ Commented Apr 29, 2015 at 9:34
  • \$\begingroup\$ Epic. I assumed it was something like that, I just wasn't sure. I appreciate it. Thanks! \$\endgroup\$ Commented Apr 29, 2015 at 18:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.