Hi Jani

The def random_generator(n): here n parameter is any number which i will
get from my request in a function.
Now when i will get the number let say 101 i will pass this 101 in my
random_generator(n) so it becomes random_generator(101) .

Now in return it should give me 6-digit number. If the 101 comes again in
that function it will generate the same random number.

I read about random.seed but how can i relate that in my case.

Thanks  for help.



On Wed, Mar 21, 2012 at 1:01 PM, Jani Tiainen <rede...@gmail.com> wrote:

> 21.3.2012 9:19, Nikhil Verma kirjoitti:
>
>  Hi All
>>
>> I want to generate a fix 6-digit random number from a function.
>>
>> eg :-
>>
>>      def random_generator(n):
>>           # do domething great
>>           return '6-digit random number'
>>
>>     output examples
>>  >>>random_number(6) # n is the input number that i will get from my
>> request
>>  >>>987657
>>
>>  >>>random_number(100)
>>  >>>987647
>>
>>  >>>random_number(6) # if the same input comes again it would generate a
>> same random number
>>  >>>987657
>>
>> If the same input cannot be generated any other way to do this part
>>
>> Any help would be appreciated.
>>
>>
> It seems that you're initializing pseudorandom generator with same seed
> number. So yes, sequence of generated numbers will be same.
>
> so doing something like this:
>
> from random import choice # Initializes from current time.
>
> def random_digits():
>    return [choice('0123456789') for i in range(7)]
>
> or if you need it:
>
> from random import randint # Initializes from current time.
>
> def random_int():
>    return randit(100000, 999999)
>
>
> Note that pseudorandom generator is only initialized first time import
> happens. After that you can set it manually using
> random.seed([x]) function.
>
> --
>
> Jani Tiainen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com <django-users%2bunsubscr...@googlegroups.com>.
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to