By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

random number between 0 and 20

P: n/a
How can I generate a random number between 0 - 20 and store the number
in nrrandom?

Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 20 Apr 2005 08:15:02 -0700, rumours say that
al*****************@gmail.com might have written:
How can I generate a random number between 0 - 20 and store the number
in nrrandom?


Just choose a random number yourself, eg. nrrandom=17 (just kidding :)
import random

nrrandom = random.randint(0,20)

See also the random.randrange function.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 19 '05 #2

P: n/a
al*****************@gmail.com wrote:
How can I generate a random number between 0 - 20 and store the number
in nrrandom?


Assuming its inclusive..
from random import randint
nrrandom = randint(0,20)


Will McGugan
--
http://www.willmcgugan.com
"".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c
in "jvyy*jvyyzpthtna^pbz" ] )
Jul 19 '05 #3

P: n/a
al*****************@gmail.com wrote:
How can I generate a random number between 0 - 20 and store the number
in nrrandom?


You would use the "random" module from the standard
library. It has a randint() method that should do
the job. Read the docs for more.

Assigning to nrrandom? Is that just a variable
name? Have you read the tutorial, which covers
basic things like assignment?

-Peter
Jul 19 '05 #4

P: n/a
Yes I know about assigning and all that. I just stated the name of the
variable so that people could easily explain how to create the random
number. I needed it to practice Python. I just finished making a number
guess program. I just finished it. It was much easier to do then I
thought it would be.

Jul 19 '05 #5

P: n/a
On Wed, 20 Apr 2005 11:10:21 -0400, rumours say that Peter Hansen
<pe***@engcorp.com> might have written:
NNTP-Posting-Date: Wed, 20 Apr 2005 10:20:45 -0500
Date: Wed, 20 Apr 2005 11:10:21 -0400


Based on these headers from your message, plus the fact that you
answered five minutes before aleksander asked his question, you might
want to either check your computer clock for accuracy or return the time
machine to Guido...
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.