Can't Generate Random #

chris at onca.catsden.net chris at onca.catsden.net
Mon Feb 5 14:48:37 EST 2001


On Mon, 5 Feb 2001 jimmypop181 at my-deja.com wrote:

> Does somebody know how to generate a random number in
> Python?  I read the docs and it says rand(x, y) should do it.  But
> whenever I try that, It says that "there is no variable named rand".
> This also happens when trying to get the Square Root.  Please
> help.

Are you sure you're reading the /python/ documentation?? :) I've no idea
where you got 'rand' from.

import whrandom

r = whrandom.randint(a,b)  # Depricated
r = whrandom.randrange(a,b) # Better, gives you a random integer [a,b)

import math
i = math.sqrt(j)

or

from math import *
i = sqrt(j)



   ("`-/")_.-'"``-._        Ch'marr, a.k.a.
    . . `; -._    )-;-,_`)  Chris Cogdon <chmarr at furry.org.au>
   (v_,)'  _  )`-.\  ``-'
  _.- _..-_/ / ((.'       FC1.3: FFH3cmA+>++C++D++H++M++P++R++T+++WZ++Sm++
((,.-'   ((,/   fL               RLCT acl+++d++e+f+++h++i++++jp-sm++





More information about the Python-list mailing list