[Tutor] Generating random in a user specified range.
adam at monkeez.org
Tue Apr 27 09:21:57 EDT 2004
I'm trying to develop an app where the user can specify the range in
which a random number will be generated from.
So far, I have two functions; range collects the range in which the
random number is to be generated from and generate number is the one
which creates the number. Range produces a list, which holds the top and
bottom number which is returned and then is passed to generatenumber to
create a number.
However, I seem to have a problem - I get an error using
random.randint(a,b) and with random.randrange(a,b). It seems that it
might be fussy accepting parts of a list as the argument. I've tried
converting them to integers and then passing the interger, but it still
Any advice on what I can do to fix this?
The driving code is:
range = range()
raw_input("click ok to carry ok")
target = generatenumber(range) #kicks the whole thing off
strtop = raw_input("What is your top number?")
strbottom = raw_input("What is your bottom number?")
top = int(strtop)
bottom = int(strbottom)
range = [bottom, top]
print "range top is ", range
print "range bottom is ", range
top = int (range)
bottom = int (range)
target = random.randrange(range, range) # and I've also tried
print "Target is ", target
ok = raw_input("please press enter to continue")
More information about the Tutor