random.sample guarantees no repetition ("sampling without replacement", per the docs); is this condition part of your specs?
As expressed (without any word "distinct" to indicate lack of repetition), I'd do:
import random
import string
def generate_pins(length, count):
return [''.join(random.choice(string.digits) for x in xrange(length))
for x in xrange(count)]
With an additional condition that all the pins returned be unique:
def generate_pins(length, count, alphabet=string.digits):
alphabet = ''.join(set(alphabet))
if count > len(alphabet)**length:
raise ValueError("Can't generate more than %s > %s pins of length %d out of %r" %
count, len(alphabet)**length, length, alphabet)
def onepin(length):
return ''.join(random.choice(alphabet) for x in xrange(length))
result = set(onepin(length) for x in xrange(count))
while len(result) < count:
result.add(onepin(length))
return list(result)
assuming that the specs require you to return a list.
Edit: given the OP's late clarification and spec changes, the second answer looks good, except string.ascii_lowercase + string.digits (or some variants thereof e.g. if both lowercase and uppercase ASCII letters are desired) should be used in onepin. You should specify better exactly what "alphabet" string you want to draw characters from (maybe pass it to generate_pins as an argument, with None indicating generate_pins should pick a default alphabet such as e.g. string.digits).
Further edit: added optional alphabet argument and checks about number of distinct pins that can be generated given length and that alphabet.