3
$\begingroup$

I am new to web development.

I am still on planning stage. One of the question that bug me is, lets say: the username can only contains 8 characters and each characters is not allowed special characters (@#$%^&), it only allows lower case "a-z", upper case "A-Z", and numerical number from "0-9". How many users I can have and how do u calculate it?

Case 1: Characters cannot be repeated eg "abcdefgh", "a1b2c3d4" etc

Case 2: Characters can be repeated, eg. "AAbbccdd", "a1b1c1D1" etc

FYI, the 8 just a sample number, of course the bigger number I provide, the better it is, but I am just curious and my math sucks :(

(I assume, need to use permutations??)

1 Answers 1

7

There are 26 uppercase letters, 26 lowercase letters, and 10 numerical digits, giving 62 possibilities for each of the eight characters. So there are $62\times 62\times \ldots \times 62 = 62^8$ possible usernames, which is a massive number.

This is in case 2, when anything goes. In case 1, once you have chosen a character, you are left with 61 possibilities for the next, then 60 possibilities for the next, giving the answer as $62\times 61\times \ldots \times 55$ usernames.

In general, therefore, with a string of $n$ characters you have $62^n$ possible usernames. With no repetitions, this becomes $\frac{62!}{(62-n)!}$ usernames.

  • 0
    Your answer was quicker and has the general case as well, I will delete mine. I am glad, however, to see that I did not make any mistakes here. I usually do... :-)2011-05-07
  • 0
    I understand case 2, pretty straight-forward: 62^8, but your case 1 abit confuse, are you saying the possibility are: 62*61*60*59*58*57*56*55?? Is it same as @Asaf answer?2011-05-07
  • 0
    @Asaf, please dont delete your answer. You answer might be helpful to others users (I guess). But, as @Fahad answer first, and if its proven correct, I need to choose his answer as best answer, bcuz he is faster than you. Hope you dont mind.2011-05-07
  • 0
    Yes that's it. You cannot use any character you've used before, so the number of possibilities goes down each time. I'm fairly sure Asaf wrote the same thing.2011-05-07
  • 0
    @FailMath: Yes, the answer is the same. Essentially what happens is that you have 62 options for the first letter, than you have 61 for the second (all but the one you used) and so on. This goes on to 62-7=55 as your eighth choice.2011-05-07
  • 2
    @FailMath: My answer was exactly as Fahad's only without regarding the general case. I don't see how two duplicate answers are useful here. :-)2011-05-07