Skip to content

Comment on Corkboard app, all in HTML/CSS/Javascriptparent

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 :)

    id=''.join(Random().sample(string.ascii_lowercase,10))

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.