2 ms·
id=''.join(Random().sample(string.ascii_lowercase,10))
by Kilimanjaro 16y ago
id=''.join(Random().sample(string.ascii_lowercase,10))
- lvh 16y agoNot 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))
- Kilimanjaro 16y agoHmm, 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.