random number between 0 and 20

Discussion in 'Python' started by Peter Hansen, Apr 20, 2005.

  1. Peter Hansen

    Peter Hansen Guest

    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
    Peter Hansen, Apr 20, 2005
    #1
    1. Advertising

  2. Peter Hansen

    Guest

    How can I generate a random number between 0 - 20 and store the number
    in nrrandom?
    , Apr 20, 2005
    #2
    1. Advertising

  3. On 20 Apr 2005 08:15:02 -0700, rumours say that
    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...
    Christos TZOTZIOY Georgiou, Apr 20, 2005
    #3
  4. Peter Hansen

    Will McGugan Guest

    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" ] )
    Will McGugan, Apr 20, 2005
    #4
  5. Peter Hansen

    Guest

    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.
    , Apr 20, 2005
    #5
  6. On Wed, 20 Apr 2005 11:10:21 -0400, rumours say that Peter Hansen
    <> 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...
    Christos TZOTZIOY Georgiou, Apr 20, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xeys_00
    Replies:
    12
    Views:
    852
    Jonathan Arnold
    Apr 11, 2005
  2. globalrev
    Replies:
    4
    Views:
    756
    Gabriel Genellina
    Apr 20, 2008
  3. sintral
    Replies:
    9
    Views:
    4,330
    Ben Bacarisse
    Dec 7, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    658
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,158
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page