If you want to use this to allow players to find each other online, you might want to generate the random code on the server, to ensure it is unique (and also associate it with the player's account).
Also, if there is a chance that these random codes will be typed or written (as opposed to being exclusively copied-and-pasted), you might want to avoid using characters that look similar, like zero (0) and upper-case o. Same with one, upper-case i, and lower-case l (L). exuin's suggestion to use an array makes it easy to remove characters you want to avoid.
It might also make sense to avoid using both upper and lower-case letters, since mixing up case is easy to do.
All that does mean you might need to make the random codes longer to ensure there are enough unique values.