generate random digits with length of 5
Gary M. Josack
gary at byoteki.com
Sun Sep 28 22:20:09 CEST 2008
Gary M. Josack wrote:
> Aaron "Castironpi" Brady wrote:
>> On Sep 28, 2:59 pm, sotirac <soti... at gmail.com> wrote:
>>> Wondering if there is a better way to generate string of numbers with
>>> a length of 5 which also can have a 0 in the front of the number.
>>> random_number = random.sample([0,1,2,3,4,5,6,7,8,9], 5) # choose 5
>>> code = 'this is a string' + str(random_number) +
>>> str(random_number) + str(random_number) + str(random_number)
>>> + str(random_number)
> This produces numbers other than 5 digit numbers. making the start
> number 10000 should be fine.
nevermind. my brain is tired tonight. this is the best solution.
More information about the Python-list