So you initialize randomnumber library everytime with your custom seed:
def random_generator(x):
random.seed(x) # Set seed to fixed value
return random.randint(100000, 999999)
But as you already know, that has nothing to do with randomness. You
return always the same number so you may use much more
lightweight solutions to calculate your 6 digit numbers.
21.3.2012 10:20, Nikhil Verma kirjoitti:
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
<mailto: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
<mailto:django-users@googlegroups.com>.
To unsubscribe from this group, send email to
django-users+unsubscribe@__googlegroups.com
<mailto: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.
--
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.