random number

Nikhil Verma varma.nikhil22 at gmail.com
Mon Mar 26 08:50:44 CEST 2012


Hi

I want something to achieve like this :-

def random_number(id): # I am passing it from request
    # do something
    return random_number

Output

random_number(5)
AXR670

One input that is a number in return you are getting 6 digit alphanumeric
string.

I tried this
s = '%06d' % random.randint(0, 999999)

it gives : '192862' (a string )

Thanks in advance.


On Mon, Mar 26, 2012 at 11:47 AM, Daniel da Silva <ddasilva at umd.edu> wrote:

> If you want it as an int:
> random.randint(100000, 999999)
>
> Or as a string:
> s = '%06d' % random.randint(0, 999999)
>
>
>
> On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma <varma.nikhil22 at gmail.com>wrote:
>
>> Hi All
>>
>> How can we generate a 6 digit random number from a given number ?
>>
>> eg:-
>>
>> def number_generator(id):
>>     random.randint(id,999999)
>>
>> When i am using this it is sometimes giving me five digit and sometimes 6
>> . I want to avoid encryption . Can i have alphanumeric 6 digit random
>> number from this .
>>
>> Thanks in advance
>>
>> --
>> Regards
>> Nikhil Verma
>> +91-958-273-3156
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120326/4808e50c/attachment.html>


More information about the Python-list mailing list