I see this type of ID everywhere and I'm curious as to how they are created and how "random" they are (the chances of generating two of the same). A python snippet would be great, of course :)
Not really. Random.sample samples from a population multiple times: that means no doubles (unless they were in the population as well). Try it: sample 30 times from string.ascii_lowercase. Since you did it with 10, less than len(population), it didn't croak, but it also doesn't get you the numbers mentioned above.
Here's one I like better: "".join(random.choice(string.ascii_lowercase) for _ in xrange(len))
Comments
I see this type of ID everywhere and I'm curious as to how they are created and how "random" they are (the chances of generating two of the same). A python snippet would be great, of course :)
Not really. Random.sample samples from a population multiple times: that means no doubles (unless they were in the population as well). Try it: sample 30 times from string.ascii_lowercase. Since you did it with 10, less than len(population), it didn't croak, but it also doesn't get you the numbers mentioned above.
Here's one I like better: "".join(random.choice(string.ascii_lowercase) for _ in xrange(len))
Hmm, if that's the case then 26x25x24... still gives you twenty trillion unique ids with non-repeating chars. Not bad after all.
Will have that in mind.