random.randint() generates same numbers
#1
the code bellow runned repeatedly generates ten different numbers but the same numbers as in last run. what do i do to generate different numbers?

Quote:import random

random.seed()
for i in range(10):
print random.randint(1, 100),

any help appreciated!
Reply
#2
hi.

i never used the random function in python.
i think you have to do something like this:
Quote:import random,time

random.seed()
for i in range(10):
print random.randint(1, time.time())
time.sleep(1)
(untested and dirty Wink )
Reply
#3
i don’t think the sleep() will do it, at least not where it’s placed. i changed the code a bit (see bellow) and it did it for me.

Quote:import random, time

random.seed(time.clock())
for i in range(10):
print random.randint(1, 100),
Reply
#4
i just tried random stuff on my pc that runs python 2.4.
in some strange way, nothing in the random module works.
did you get this running on pc?
Reply
#5
i also tried on pc with python 2.4 now.
all works fine and the examplecode in the first post dont give's "the same numbers as in last run".
i get different numbers in every run.
Reply
#6
hahahahaha
stupid me. :nuts:
i named the script random.py!
because of that, i imported my own script, and not the python random module!



Reply
#7
i’ve only tested the scripts on the xbox, but i’ve played around on windows in interactive mode and it returns different numbers. random.seed() (no argument) should use current system time (http://docs.python.org/lib/module-random.html). maybe this doesn’t work on the xbox, but probably i’ve misunderstood something.
Reply
#8
i had this trouble try random.seed(time.time())
for sum reason (although you shouldn't need to supply this) it works.
read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
Reply

Logout Mark Read Team Forum Stats Members Help
random.randint() generates same numbers0